Compresses linked and inline javascript or CSS into a single cached file.
Switch branches/tags
upstream/0.9.2 upstream/0.6a7 hudson-django_compressor-38 hudson-django_compressor-37 hudson-django_compressor-37-SUCCESS hudson-django_compressor-36 hudson-django_compressor-36-SUCCESS hudson-django_compressor-35 hudson-django_compressor-34 hudson-django_compressor-33 hudson-django_compressor-32 hudson-django_compressor-31 hudson-django_compressor-30 hudson-django_compressor-30-SUCCESS hudson-django_compressor-29 hudson-django_compressor-29-SUCCESS hudson-django_compressor-28 hudson-django_compressor-28-SUCCESS hudson-django_compressor-27 hudson-django_compressor-27-SUCCESS hudson-django_compressor-26 hudson-django_compressor-26-SUCCESS hudson-django_compressor-25 hudson-django_compressor-25-SUCCESS hudson-django_compressor-24 hudson-django_compressor-24-SUCCESS hudson-django_compressor-23 hudson-django_compressor-22 hudson-django_compressor-21 hudson-django_compressor-20 hudson-django_compressor-19 hudson-django_compressor-19-SUCCESS hudson-django_compressor-18 hudson-django_compressor-17 hudson-django_compressor-17-SUCCESS hudson-django_compressor-14 hudson-django_compressor-13 hudson-django_compressor-13-SUCCESS hudson-django_compressor-12 hudson-django_compressor-12-SUCCESS hudson-django_compressor-11 hudson-django_compressor-11-SUCCESS hudson-django_compressor-10 hudson-django_compressor-10-SUCCESS hudson-django_compressor-9 hudson-django_compressor-9-SUCCESS hudson-django_compressor-8 hudson-django_compressor-8-SUCCESS hudson-django_compressor-7 hudson-django_compressor-7-SUCCESS hudson-django_compressor-6 hudson-django_compressor-5 hudson-django_compressor-5-SUCCESS hudson-django_compressor-4 hudson-django_compressor-4-SUCCESS hudson-django_compressor-3 hudson-django_compressor-3-SUCCESS hudson-django_compressor-2 hudson-django_compressor-2-SUCCESS hudson-django_compressor-1 debian/0.9.2-0sg38 debian/0.9.2-0sg37 debian/0.9.2-0sg36 debian/0.6a7-0sg30 debian/0.6a7-0sg29 debian/0.6a7-0sg28 debian/0.6a7-0sg27 debian/0.6a7-0sg26 debian/0.6a7-0sg25 debian/0.6a7-0sg24 debian/0.6a7-0sg22 debian/0.6a7-0sg21 debian/0.6a7-0sg20 debian/0.6a7-0sg19 debian/0.6a7-0sg18 debian/0.6a7-0sg17 debian/0.6a7-0sg14 debian/0.6a7-0sg13 debian/0.6a7-0sg12 debian/0.6a7-0sg11 debian/0.6a7-0sg10 debian/0.6a7-0sg9 debian/0.6a7-0sg8 debian/0.6a7-0sg7 debian/0.6a7-0sg6 debian/0.6a7-0sg5 debian/0.6a7-0sg4 debian/0.6a7-0sg3 debian/0.6a7-0sg2 debian/0.6a7-0sg1 1.1.1 1.1 1.0.1 1.0 0.9.2 0.9.1 0.9 0.8 0.7.1 0.7
Nothing to show
Clone or download
Pull request Compare This branch is 790 commits behind django-compressor:develop.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Django Compressor

Django Compressor combines and compresses linked and inline Javascript or CSS in a Django templates into cacheable static files by using the compress template tag.

HTML in between {% compress js/css %} and {% endcompress %} is parsed and searched for CSS or JS. These styles and scripts are subsequently processed with optional, configurable compilers and filters.

The default filter for CSS rewrites paths to static files to be absolute and adds a cache busting timestamp. For Javascript the default filter compresses it using jsmin.

As the final result the template tag outputs a <script> or <link> tag pointing to the optimized file. These files are stored inside a folder and given an unique name based on their content. Alternatively it can also return the resulting content to the original template directly.

Since the file name is dependend on the content these files can be given a far future expiration date without worrying about stale browser caches.

The concatenation and compressing process can also be jump started outside of the request/response cycle by using the Django management command compress.

Configurability & Extendibility

Django Compressor is highly configurable and extendible. The HTML parsing is done using lxml or if it's not available Python's built-in HTMLParser by default. As an alternative Django Compressor provides a BeautifulSoup and a html5lib based parser, as well as an abstract base class that makes it easy to write a custom parser.

Django Compressor also comes with built-in support for CSS Tidy, YUI CSS and JS compressor, the Google's Closure Compiler, a Python port of Douglas Crockford's JSmin, a Python port of the YUI CSS Compressor cssmin and a filter to convert (some) images into data URIs.

If your setup requires a different compressor or other post-processing tool it will be fairly easy to implement a custom filter. Simply extend from one of the available base classes.

More documentation about the usage and settings of Django Compressor can be found on

The source code for Django Compressor can be found and contributed to on There you can also file tickets.

The in-development version of Django Compressor can be installed with pip install django_compressor==dev or easy_install django_compressor==dev.