Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 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:

Description

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.

STATICFILES_COMPRESSORS = {
    '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 3 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 3 years ago by russellm

  • milestone 1.3 deleted
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 3 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 3 years ago by jezdez

  • Resolution set to wontfix
  • Status changed from new to closed

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 (http://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-storage)

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 3 years ago by jezdez

  • Summary changed from [PATCH] Add support for compressors/minimizers to django.contrib.staticfiles to Add support for compressors/minimizers to django.contrib.staticfiles

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.