Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#15213 closed (wontfix)

Add support for compressors/minimizers to django.contrib.staticfiles

Reported by: Sebastian Noack Owned by:
Component: contrib.staticfiles Version: 1.3-alpha
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


It's common practice to use programs like jsmin and yui-compresser in order to compress JS and CSS files to reduce traffic and accelerate the parsing. Usually you wold compress those files when deploying the web project. When you are using django.contrib.staticfiles that would be just before or after you have called the collectstatic management command. So I thought it would be great if that mangement command could do that for you and have written the patch attached to this ticket. It adds a new setting STATICFILES_COMPRESSORS. It's a dictionary mapping filename extensions to command lines used to compress files with that extension. You can use any external program that takes the raw file on stdin and outputs compressed file to stdout. So for example if you would like to use yui-compressor, you only have to add following to your settings module.

    'js':  'yui-compressor --type js',
    'css': 'yui-compressor --type css',

Attachments (1)

Enabled-compression-of-static-files-using-an-external-programs.patch (6.4 KB) - added by Sebastian Noack 6 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 6 years ago by Russell Keith-Magee

milestone: 1.3
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

Accepting the broad concept. However, this will require a lot of thought, because there are lots of compression tools, and they have different requirements. I'm fully in favor of adding a hook to make it easy to use these compressors, but we need to make sure the hook will actually do everything it needs to do.

It's certainly not on the 1.3 milestone, though. It's a new feature for staticfiles, not a defect in the existing feature.

comment:2 Changed 6 years ago by Sebastian Noack

Every compression tool I have seen so far is able to read a file from stdin and to write the output to stdout. So I think that my patch is flexible enough for most programs. That way you can use the most common tools without the need to write a function that calls the external program. Also note that if you still want use a compressor that does not work that way you can wrap it with a simple script.

comment:3 Changed 6 years ago by Jannis Leidel

Resolution: wontfix
Status: newclosed

I'm strongly opposed to adding more than the collectstatic command to staticfiles due to the fact that there are various post processing workflows that could be applied to the collected files, not all of which are enough to be called in the serial manner collectstatic works. In other words, there is nothing that prevents you right now to do this during the rest of your deployment (see Fabric examples in our docs).

And even then, there already *is* a hook to enable post processing: the STATICFILES_STORAGE setting (

Marking as wontfix, please reopen in case there is a usecase that can't be implemented in a custom storage backend or an external script.

comment:4 Changed 6 years ago by Jannis Leidel

Summary: [PATCH] Add support for compressors/minimizers to django.contrib.staticfilesAdd support for compressors/minimizers to django.contrib.staticfiles
Note: See TracTickets for help on using tickets.
Back to Top