This release is a pre-release and may not be stable for production use.
django-compress-staticfiles
A Django static files storage backend inheriting from ManifestFilesMixin and StaticFilesStorage. Compresses, using GZip and/or Brotli, and minifies static files when running the Django collectstatic command.
What this package does:
- Compresses static files using Brotli and/or GZip. See the included filetypes heading to see which filetypes are compressed.
- Minifies JS using rJSMin.
- Minifies CSS using csscompressor.
What this package does not do:
- Does not support concatenation/bundling of JS or CSS.
- Does not support transpiling from any transpiling Javascript language.
- Does not support SASS, LESS or any other CSS preprocessor.
- This package is not a linter or tester. The collectstatic command is not the place to be linting or testing your code. The primary purpose of this package is compressing staticfiles for use in staging or production environments — minification is optional but does so by default.
- Does not delete stale files from your
STATIC_ROOTdirectory. If changes were made to some of your static files; old files will remain there. Use the--clearflag when runningcollectstaticto delete the entireSTATIC_ROOTand recreate it — check out the Django docs for more info.
Some important things to take note of:
- If
DEBUG = Truein your Django settings.py file; only the normal file is used in templates. Templates will only use the hashed and minified version of the file whenDEBUG = False. This is the behaviour of the Django staticfiles app in theurlmethod of theManifestFilesMixin. - The compressed version of the file is never used in the template. Your webserver can decide which version of the file to serve depending on the Accept-Encoding header in the request.
- This package updates the manifest JSON file created by ManifestFilesMixin with a path pointing to the hashed and minified version of each processed file where applicable.
- If there is a
.minfile to be copied to STATIC_ROOT; that file will be compressed but not re-minified. If that.minfile has a corresponding non-minified counterpart, that non-minified file will be minified and that minified file is the one that will be used to mapregular.csstoregular.min.{hash}.cssin the manifest file. - This package does not yet deal with the @import rule and url() function in CSS; therefore the value is not updated after ManifestFilesMixin handles those things — the minified file will not be referenced, only the hashed version as substituted by ManifestFilesMixin.
- The original files, for example,
somefile.csswon't be compressed tosomefile.css.gzbecause we will likely never use it. - Files smaller than 200 bytes will not be compressed.
Usage with cloud storage like Google Cloud Storage or Amazon S3:
Even though the CompressStaticFilesStorage inherits from StaticFilesStorage, which inherits from FileSystemStorage, the CompressStaticFilesMixin and MinifyFilesMixin can be used with your own storage.
Quickstart
Install the app and it's dependencies using:
pip install git+https://github.com/armandtvz/django-compress-staticfiles.git
Set the STATICFILES_STORAGE setting in your project settings.py as follows:
STATICFILES_STORAGE = 'compress_staticfiles.storage.CompressStaticFilesStorage'
You don't need to set any other settings for everything to work but for some mild customisation see the settings heading for more info.
Run the collectstatic command as you usually would:
python manage.py collectstatic
Settings
There's no need to set these settings as they have defaults — they're there
if you want them. All are True by default.
# All are True by default.
MINIFY_STATIC = True
BROTLI_STATIC_COMPRESSION = True
GZIP_STATIC_COMPRESSION = True
Included filetypes for compression
Only files ending with these extensions will be compressed:
- css
- js
- txt
- xml
- json
- svg
- md
- rst
Included filetypes for minification
- css
- js
JS Minification
The rJSMin Python package is used for JavaScript minification. See rJSMin's Github repo for docs and more information. JS is not obfuscated. Exclamation/bang comments will be retained.
CSS Minification
Exclamation/bang comments will be retained.
There might be some questions
Why not just use django-compressor or django-pipeline instead?
Though I haven't used django-compressor or django-pipeline myself; I have gone through their respective documentation. I'm sure django-compressor and django-pipeline are excellent tools and I'm sure there's a time and place to be using them.
However, this package aims to be something smaller and simpler with absolutely no configuration needed; no template tags and no extra management commands. It aims to be unobtrusive; to slide straight into the regular Django `collectstatic' management command.
Why no bundling/concatenation of JS or CSS?
Bundling is so HTTP/1.1. Join us in HTTP/2 where things are multiplexed. :) Jokes aside... If you really need bundling: it's probably best to look at something like Webpack, django-compressor or django-pipeline.
Why does this package use the ManifestFilesMixin?
For those who are unfamiliar with the ManifestFilesMixin please read the Django docs for ManifestFilesMixin and ManifestStaticFilesStorage.
Compatiblity
- Compatible with Python 3.5 and above.
- Compatible with Django 1.10 and above. Do remember that, at the time of writing, Django 2.2 and below is deprecated and therefore there is only official support for Django 2.2 and above.
- Check rJSMin's Github repo / docs for more info regarding ES6 compatibility.
Versioning
This project follows semantic versioning (SemVer).
License, code of conduct and requirements
Check the root of the repo for these files.
Metadata
Release files for django-compress-staticfiles 1.0.1b0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-compress-staticfiles-1.0.1b0.tar.gz | 13.2 kB | Without provenance | Details for django-compress-staticfiles-1.0.1b0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_compress_staticfiles-1.0.1b0-py3-none-any.whl | Python 3 | none | any | Details for django_compress_staticfiles-1.0.1b0-py3-none-any.whl |
Total release size: 41.9 kB
Release files / django-compress-staticfiles-1.0.1b0.tar.gz
| Download URL | django-compress-staticfiles-1.0.1b0.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec44f3065f07880c919ce998da7932519decf518c6baba565394853a8685f737
|
|
BLAKE2b-256 checksum How to use checksums |
64cc24ab289c1c2563033f7096fae679364b8afbceb10d53d2d070d3c7083076
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.5.2
|
Release files / django_compress_staticfiles-1.0.1b0-py3-none-any.whl
| Download URL | django_compress_staticfiles-1.0.1b0-py3-none-any.whl |
|---|---|
| Size | 28.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce6b9b766cda23c77ef1072846a60de856b4c1c29519d3e57c6cffe7281d7f04
|
|
BLAKE2b-256 checksum How to use checksums |
a0ce0d2ee24c87ecf71e3e5604827ee81d05ea3326f542df6c768d111b9dedaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.5.2
|
Security for django-compress-staticfiles 1.0.1b0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.