Skip to main content

Django Compressor

https://codecov.io/github/django-compressor/django-compressor/coverage.svg?branch=develop https://img.shields.io/pypi/v/django_compressor.svg 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 filters.

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 manage.py 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 django-compressor.readthedocs.org.

The source code for Django Compressor can be found and contributed to on github.com/django-compressor/django-compressor. There you can also file tickets.

The in-development version of Django Compressor can be installed with pip install git+https://github.com/django-compressor/django-compressor.git

Metadata

Release files for django-compressor 4.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-compressor 4.7.0
File Size Uploaded Provenance Actions
django_compressor-4.7.0.tar.gz 425.7 kB Without provenance Details for django_compressor-4.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-compressor 4.7.0
File Interpreter ABI Platform Actions
django_compressor-4.7.0-py3-none-any.whl Python 3 none any Details for django_compressor-4.7.0-py3-none-any.whl

Total release size: 573.5 kB

Release files / django_compressor-4.7.0.tar.gz

Download URL django_compressor-4.7.0.tar.gz
Size 425.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c9fd24ef08c0525a9f65241d3b3154c0824d77e2de5e1d9d213b94496d0f4e03
BLAKE2b-256 checksum
How to use checksums
64d1981849843c132f1c4537e8b0ad5b66d0947b08b51103b222b19d88a76c1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / django_compressor-4.7.0-py3-none-any.whl

Download URL django_compressor-4.7.0-py3-none-any.whl
Size 147.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efcd895467e41251b775fbfa440dd06db61c01e6c503ff93cfc10e2772c3fa2a
BLAKE2b-256 checksum
How to use checksums
97f9d6073169abc12f04fa5c7fc01dfcb4fffbccb0fd3c0fe97999558501dbfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for django-compressor 4.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.7.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page