Package: django-compress-staticfiles
django-compress-staticfilesA Django static files storage backend inheriting fromManifestFilesMixinandStaticFilesStorage. Compresses, using GZip and/or Brotli, and minifies
static files when running the Djangocollectstaticcommand.What this package does:Compresses static files usingBrotliand/or GZip. See theincluded
filetypesheading to see which filetypes are compressed.Minifies JS usingrJSMin.Minifies CSS usingcsscompressor.What this package doesnotdo:Does not support concatenation/bundling of JS or CSS.Does not support transpiling from any transpiling Javascript language.Does not supportSASS,LESSor 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 yourSTATIC_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:IfDEBUG = 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 Djangostaticfilesapp 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 hashedandminified 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 filewillbe 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.QuickstartInstall the app and it's dependencies using:pip install git+https://github.com/armandtvz/django-compress-staticfiles.gitSet theSTATICFILES_STORAGEsetting 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 thecollectstaticcommand as you usually would:python manage.py collectstaticSettingsThere's no need to set these settings as they have defaults â€” they're there
if you want them. All areTrueby default.# All are True by default.MINIFY_STATIC=TrueBROTLI_STATIC_COMPRESSION=TrueGZIP_STATIC_COMPRESSION=TrueIncluded filetypes for compressionOnly files ending with these extensions will be compressed:cssjstxtxmljsonsvgmdrstIncluded filetypes for minificationcssjsJS MinificationTherJSMin Python packageis 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 MinificationExclamation/bang comments will be retained.There might be some questionsWhy not just usedjango-compressorordjango-pipelineinstead?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-compressorordjango-pipeline.Why does this package use theManifestFilesMixin?For those who are unfamiliar with the ManifestFilesMixin please read the
Django docs forManifestFilesMixinandManifestStaticFilesStorage.CompatiblityCompatible 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 Githubrepo/ docs for more info regarding ES6
compatibility.VersioningThis project followssemantic versioning(SemVer).License, code of conduct and requirementsCheck the root of the repo for these files.