precompressed is a pluggable application for Django developers who want to serve precompressed (gzipped) static files.
- Alters the behavior of
./manage.py collectstaticto save gzipped copies of specified static files (by default*.cssand*.js). - When the client supports
Content-Encoding: gzipand{% static %}is used then the rendered URI will refer to the precompressed version of the static file. - Works with CachedFilesMixin and storages.backends.s3boto.S3BotoStorage
pip install django-precompressed- Add
precompressedto yoursettings.INSTALLED_APPSbefore'django.contrib.staticfiles'so that precompressed's version of{% static %}will be utilized. - Set
settings.STATICFILES_STORAGEto one that suits your needs (see Storages below). - Run
./manage.py collectstaticto generate precompressed copies. - Utilize
{% static %}template tag when referencing static files where applicable.
All settings are optional and specified via the settings.PRECOMPRESSED_SETTINGS dictionary.
GZIP_PATTERNSis a tuple of file patterns that are to be gzipped. Defaults to('*.css', '*.js')DEFAULT_COMPRESS_LEVELis a number 0-9 that specifies the default compression level. Defaults to 9.accepts_gzip(request)is a function that returns True if the client supportsContent-Encoding: gzipget_gzipped_name(name)is a function that translates filenames and URIs to the precompressed version. Defaults to resource.ext becomes resource.gz.extshould_save_gzipped_copy(path)is a function that returns True if the specified file should have a precompressed copy saved. Defaults to file matches GZIP_PATTERNS?
precompressed.storage.PrecompressedStaticFilesStorage
precompressed.storage.CachedPrecompressedStaticFilesStorage
These storages extend Django's builtin StaticFilesStorage to provide the described precompression behavior. If you use this you'll probably want to configure your webserver to add the Content-Encoding: gzip header when serving precompressed files.
precompressed.storage.s3boto.PrecompressedS3BotoStorage
precompressed.storage.s3boto.CachedPrecompressedS3BotoStorage
These storages extend django-storages' S3BotoStorage to provide described precompression behavior for files stored on Amazon Simple Storage Service (Amazon S3)
The Cached prefixed versions of each utilize CachedFilesMixin and therefore store hashed copies of static files in addition to the precompressed versions.