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'
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?
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'
)
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.
See: http://code.larlet.fr/django-storages/src/e27c8b61ab57e5afaf21cccfee005c980d89480f/storages/backends/s3boto.py?at=default#cl-236
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With