Sign inDemoInstall


Package Overview
File Explorer

Install Socket

Protect your apps from supply chain attacks



('Compresses linked and inline JavaScript or CSS into single cached files.',)




Django Compressor

.. image::

.. image::

.. image::
    :alt: Build Status

Django Compressor processes, combines and minifies linked and inline
Javascript or CSS in a Django template into cacheable static files.

It supports compilers such as coffeescript, LESS and SASS and is
extensible by custom processing steps.

How it works
In your templates, all HTML code between the tags ``{% 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

The default filter for CSS rewrites paths to static files to be absolute.
Both Javascript and CSS files are by default concatenated and minified.

As the final step the template tag outputs a ``<script>`` or ``<link>``
tag pointing to the optimized file. Alternatively it can also
inline the resulting content into the original template directly.

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

For increased performance, the concatenation and compressing process
can also be run once manually outside of the request/response cycle by using
the Django management command `` compress``.

Configurability & Extensibility

Django Compressor is highly configurable and extensible. 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
`YUI CSS and JS`_ compressor, `yUglify CSS and JS`_ compressor, Google's
`Closure Compiler`_, a Python port of Douglas Crockford's JSmin_, a Python port
of the YUI CSS Compressor csscompressor_ 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 git+``

.. _BeautifulSoup:
.. _lxml:
.. _html5lib:
.. _YUI CSS and JS:
.. _yUglify CSS and JS:
.. _Closure Compiler:
.. _JSMin:
.. _csscompressor:
.. _data URIs:


Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc