5

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?

1
  • Can I ask why you define COMPRESS_STORAGE twice? Commented Apr 30, 2015 at 17:35

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.