Sunday, March 27, 2011

Issues using django-compress and django.contrib.staticfiles from django 1.3

There is no way to use both django-compress and django.contrib.staticilfes from new django 1.3. MEDIA_URL and MEDIA_ROOT hardcoded into django-compress utility functions so here is
my fork of django-compress on github with fix.

I've added two new settings COMPRESS_URL and COMPRESS_ROOT which points by default to MEDIA_URL and MEDIA_ROOT respectively for backward compatibility.

django-compress is extremely useful tool which provide possibility to organize your JavaScript and CSS files around your project. Also there is a couple of useful features like support of YUI compressor and building of bunch of JavaScript or CSS files into one.

Read more about django-compress


  1. Hi Max,
    You should have a look at django-compressor (, from Jannis Leidel, which is also the author of django-staticfiles - which is now included in Django contrib.

  2. zyegfryed@, django-compressor is awesome but there is absolutely another approach to solve same problems. I mentioned in my post that main feature of django-compress is organization of my code - all necessary css/js files stored in configuration dictionary

  3. both solutions are not really good. they are too slow and too problematic. better is to compile/minifty/join static stylesheets and javascripts at buildtime for specified files in project.

  4. Marcin Nowak@, I'm not quite sure that you're used django-compress. It's django-oriented replacement for naked Makefiles or ant for building project at buildtime. You just need to use python synccompress and django-compress update/recreate static files. Obviously, it should be part of your deployment utility.

  5. Max, you are right. It was django-compressor not django-compress. Compressor does not have synccompress command.

    Django-compressor is crashing at runtime (even in production env) when source files are unaccessible.
    I'm still wondering about using Django for generating static files. I prefer a buildout-like solutions using c2c.recipe.cssmin, c2c.recipe.closurecompile or collective.recipe.minify. Any missing files will be reported at buildtime, not runtime.

  6. @Nowak: that's not right, django-compressor comes with a management command to do offline compression.