Skip to main content
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

Release files for django-compressor 4.3.1

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.3.1
File Size Uploaded
django_compressor-4.3.1.tar.gz 422.2 kB Details

Built distribution (wheel)

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

Total release size: 571.1 kB

Release files / django_compressor-4.3.1.tar.gz

Download URL django_compressor-4.3.1.tar.gz
Size 422.2 kB
Tags Source
SHA-256 checksum
How to use checksums
68858c0da6cc099cc29a022d86c3ba8aed114da9d709eeceb0d7b8181b5f8942
BLAKE2b-256 checksum
How to use checksums
2d401c8b0073bd5e4b4395137191ab5e77f905b309c3bc75f1d6f97d0b6d9bd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / django_compressor-4.3.1-py2.py3-none-any.whl

Download URL django_compressor-4.3.1-py2.py3-none-any.whl
Size 149.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2c451174acb6f083054af7c8089376599b22d6380bd60311f78ec3fed79acc8e
BLAKE2b-256 checksum
How to use checksums
983c8abbd640048cea29321889da4c89ea2d60c0c6a1cfaac617ecce6f0ed17f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

4.6.0

2 release files

4.5.1

2 release files

4.5

2 release files

4.4

2 release files

This release

4.3.1 This release

2 release files

4.3

2 release files

4.2

2 release files

4.1

2 release files

4.0

2 release files

3.1

2 release files

3.0

2 release files

2.4.1

2 release files

2.4

2 release files

2.3

2 release files

2.2

2 release files

2.1.1

2 release files

2.1

2 release files

2.0

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

1 release file

1.2

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1

1 release file

1.0.1

1 release file

1.0

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9

1 release file

0.8

1 release file

0.7.1

1 release file

0.7

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6

1 release file

0.5.3

1 release file

0.5.2

1 release file

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