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
manage.py 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.