File compression in Divio Django applications¶
Default behaviour in our projects¶
By default, we apply gzip compression to:
- Django-served content, such as HTML files
- static files, when
This compression can be disabled by setting the
DISABLE_GZIP environment variable to
For Django-served content, we apply Django’s
When gzip is disabled, gzipped versions of static files are not used (though they are still collected). A default Django storage class is used instead.
DEBUG = True¶
DEBUG = True, the non-gzipped versions of the files are loaded by templates, whether or not
DISABLE_GZIP has been applied.
Using Django Compressor¶
Django Compressor is a popular tool for additional compression functionality (for example, consolidation of multiple files into one).
When using Django Compressor, note that:
- offline compression must be used
- static files must be compressed before collection (
python manage.py compressmust come before
To verify correct and expected operation of Django Compressor, use the local server in live configuration, taking note to disable volume mapping that would affect the collected compressed files.