Django的COM pressor使用gzip服务的JavaScript [英] Django compressor using gzip to serve javascript
问题描述
我想成为gzip压缩文件从Amazon S3的。 这是我的settings.py:
I am trying to serve gzip files from amazon s3. This is my settings.py:
AWS_IS_GZIPPED = True
AWS_PRELOAD_METADATA = True
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_STORAGE_BUCKET_NAME = 'elasticbeanstalk-eu-west-1-2051565523'
STATIC_URL = 'https://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
COMPRESS_OFFLINE = True
COMPRESS_ENABLED = True
COMPRESS_URL = STATIC_URL
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.CSSMinFilter'
]
COMPRESS_JS_FILTERS = [
'compressor.filters.jsmin.JSMinFilter',
]
COMPRESS_STORAGE = 'compressor.storage.GzipCompressorFileStorage'
当我这样做的Django为每一位* .js文件中创建*。广州文件和*的CSS COM pressed但奇怪的只有* .css文件都担任gzip压缩。我可以看到在AWS S3的.css文件有内容编码:gzip和的* .js没有。这是怎么回事吗?
When I do this django creates *.gz files for every *.js and *.css compressed but strangely only the *.css files are served as gzip. I can see on the aws s3 that the .css files have the Content-Encoding: gzip and the *.js don't. What is going on here?
推荐答案
我有同样的问题,并能够通过添加文/ JavaScript的
来解决这对 GZIP_CONTENT_TYPES
像这样设置:
I had the same issue and was able to resolve this by adding text/javascript
to the GZIP_CONTENT_TYPES
setting like so:
GZIP_CONTENT_TYPES = (
'text/css',
'application/javascript',
'application/x-javascript',
'text/javascript'
)
我不知道为什么,但 GZIP_CONTENT_TYPES
中的默认值 Django的货仓== 1.1.8
似乎不包括文/ JavaScript的
如此看来的Django-COM pressor
跳过GZIP为COM pressed .js文件与此内容类型。
I'm not sure why, but the default value of GZIP_CONTENT_TYPES
in django-storages==1.1.8
does not seem to include text/javascript
so it seems django-compressor
skips GZIP for compressed .JS files with this content type.
请参阅:<一href="http://$c$c.larlet.fr/django-storages/src/e27c8b61ab57e5afaf21cccfee005c980d89480f/storages/backends/s3boto.py?at=default#cl-236" rel="nofollow">http://$c$c.larlet.fr/django-storages/src/e27c8b61ab57e5afaf21cccfee005c980d89480f/storages/backends/s3boto.py?at=default#cl-236
这篇关于Django的COM pressor使用gzip服务的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!