问题
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?
回答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).
Be aware it will load the compressed files only on production (with debug=false and offline compression enable)
来源:https://stackoverflow.com/questions/31389584/gulp-css-minify-gzip-django-compressor-not-working