Gulp CSS minify& gzip + django-compressor不工作 [英] Gulp CSS minify & gzip + django-compressor not working

查看:165
本文介绍了Gulp CSS minify& gzip + django-compressor不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力缩小和压缩我的css(和后来的js)并提供服务。为此,我首先使用gulp进行缩小并压缩,然后使用django-compression服务gzip文件(因此只有http请求)。



我非常遵循本指南:
http://www.revsys.com/blog/2014/oct/21/ultimate-front-end-development-setup/



直接使用gzip压缩文件效果很好,但是当我尝试使用django-compression进行分组时,我会收到以下错误:



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
sig:'utf8'codec
无法解码位置1中的字节0x8b:无效的起始字节

其中对应于compress标签:

  {%compress css%} 
< link rel = stylesheethref ={{STATIC_URL}} mincss / filename.min.css.gz>
...更多文件
{%endcompress%}

我是99%的确定gzipped生成的文件是正确的。它们是us-ascii(utf-8的子集),它们包含* .min.css文件。



我的相关设置(我知道)的问题与指南中列出的相同。唯一的区别是,在指南中,他包括这样的css文件:

  {%compress css%} 
< link rel =stylesheethref ={%staticstylesheets / main.css%}/>
< link rel =stylesheethref ={%staticstylesheets / some-other.css%}/>
{%endcompress%}

但是这种方式(虽然它有效)不使用gzip压缩的文件,甚至不是最小的文件。我缺少什么?

解决方案

包含的文件不能包含gzipped的扩展名。只需提供文件名(* .css),压缩器将自动检查并加载文件的gzip压缩版本(需要具有相同的名称加上.gz)。



意识到它只会在生产(加上debug = false和离线压缩启用))加载压缩文件


I am trying to minify and compress my css (and later js) and serve it. To this end I first minify and compress it with gulp and then serve the gzipped files with django-compressor (so only http request will be made).

I pretty much followed this guide: http://www.revsys.com/blog/2014/oct/21/ultimate-front-end-development-setup/

Using directly the gzipped files works good, however when I try to group them with django-compressor I get the following error:

UncompressableFileError at /
UnicodeDecodeError while processing '..../static/mincss/filename.min.css.gz' 
with charset utf-8-sig: 'utf8' codec 
can't decode byte 0x8b in position 1: invalid start byte

Which corresponds with the compress tag on:

    {% compress css %}
      <link rel="stylesheet" href="{{ STATIC_URL }}mincss/filename.min.css.gz">
...more files
    {% endcompress %}

I'm 99% sure that the gzipped generated files are correct. They are us-ascii (subset of utf-8) and they contain the *.min.css file.

My relevant settings (that I know of) for the issue are the same as the ones listed on the guide. The only difference is that on the guide he includes the css files like this:

{% compress css %}
<link rel="stylesheet" href="{% static "stylesheets/main.css" %}" />
<link rel="stylesheet" href="{% static "stylesheets/some-other.css" %}" />
{% endcompress %}

But this way (though it works) doesn't use the gzipped files, not even the minified ones. What am I missing?

解决方案

The included file must not contain the gzipped extension. Just providing the file name (*.css) compressor will automatically check and load de gzipped version of the file (needs to have the same name plus .gz).

Be aware it will load the compressed files only on production (with debug=false and offline compression enable)

这篇关于Gulp CSS minify&amp; gzip + django-compressor不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆