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).
我正在尝试缩小和压缩我的css(以及后来的js)并提供它。为此,我首先使用gulp对其进行压缩和压缩,然后使用django压缩器为gziked文件提供服务(因此只发出http请求)。
I pretty much followed this guide: http://www.revsys.com/blog/2014/oct/21/ultimate-front-end-development-setup/
我基本上遵循了这个指南: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:
直接使用gzip文件很好,但是当我尝试用django-压缩机将它们分组时,我得到了以下错误:
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.
我确信gzipped生成的文件是正确的。它们是us-ascii (utf-8的子集),它们包含*.min。css文件。
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:
我对这个问题的相关设置(我所知道的)与指南中列出的设置相同。唯一的不同之处在于,在指南中他包含了如下css文件:
{% 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?
但是这种方式(尽管它是有效的)不使用gziked文件,甚至是缩小的文件。我缺少什么?
1 个解决方案
#1
1
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).
所包含的文件不能包含gzip扩展名。只要提供文件名(*.css)压缩器,就会自动检查并加载gziked版本的文件(需要有相同的名称加上.gz)。
Be aware it will load the compressed files only on production (with debug=false and offline compression enable)
请注意,它将只在生产环境中加载压缩文件(启用debug=false和脱机压缩)
#1
1
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).
所包含的文件不能包含gzip扩展名。只要提供文件名(*.css)压缩器,就会自动检查并加载gziked版本的文件(需要有相同的名称加上.gz)。
Be aware it will load the compressed files only on production (with debug=false and offline compression enable)
请注意,它将只在生产环境中加载压缩文件(启用debug=false和脱机压缩)