Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompressedStaticFilesMixin compresses each CSS file multiple times #150

Closed
edmorley opened this issue Sep 17, 2017 · 2 comments
Closed

CompressedStaticFilesMixin compresses each CSS file multiple times #150

edmorley opened this issue Sep 17, 2017 · 2 comments

Comments

@edmorley
Copy link
Contributor

edmorley commented Sep 17, 2017

I noticed as part of #148 (by modifying CompressedStaticFilesMixin so that it passes quiet=False to Compressor to give more log output) that CSS files are run through the compressor multiple times:

$ ./manage.py collectstatic --noinput -v 3 > collectstatic.log
$ grep -e 'Brotli compressed .*\.css ' collectstatic.log | sort
Brotli compressed /home/vagrant/test/test/static/admin/css/base.31652d31b392.css (15K -> 3K)
Brotli compressed /home/vagrant/test/test/static/admin/css/base.6b517d0d5813.css (15K -> 3K)
Brotli compressed /home/vagrant/test/test/static/admin/css/base.6b517d0d5813.css (15K -> 3K)
Brotli compressed /home/vagrant/test/test/static/admin/css/base.css (15K -> 3K)
Brotli compressed /home/vagrant/test/test/static/admin/css/base.css (15K -> 3K)
Brotli compressed /home/vagrant/test/test/static/admin/css/base.css (15K -> 3K)
Brotli compressed /home/vagrant/test/test/static/admin/css/changelists.css (6K -> 1K)
Brotli compressed /home/vagrant/test/test/static/admin/css/changelists.css (6K -> 1K)
Brotli compressed /home/vagrant/test/test/static/admin/css/changelists.css (6K -> 1K)
Brotli compressed /home/vagrant/test/test/static/admin/css/changelists.f6dc691f8d62.css (6K -> 1K)
Brotli compressed /home/vagrant/test/test/static/admin/css/changelists.f6dc691f8d62.css (6K -> 1K)
Brotli compressed /home/vagrant/test/test/static/admin/css/changelists.f6dc691f8d62.css (6K -> 1K)
...

This is due to a bug in Django's HashedFilesMixin, for which I've filed an upstream issue:
https://code.djangoproject.com/ticket/28607

The upstream bug only affects "adjustable files" (ie files that HashedFilesMixin has to do a second pass on, in case they cross-reference other files that have been hashed, so might need renaming with a new hash) - which currently is just *.css. However it still has a significant impact on the number of compressions performed:

$ grep 'Brotli compressed' collectstatic.log | wc -l
370
$ grep 'Brotli compressed' collectstatic.log | sort -u | wc -l
276

Even though this is due to an upstream bug, it would be good to work around it in the meantime.

@evansd
Copy link
Owner

evansd commented Nov 1, 2017

I've got a workaround for this, but the patch still needs a bit of work before I push it up.

@evansd
Copy link
Owner

evansd commented Jul 16, 2018

Finally fixed via this series of commits:
c374573...9e02fa5

@evansd evansd closed this as completed Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants