Skip to main content

Compresses linked and inline JavaScript or CSS into single cached files.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_compressor-4.6.0.tar.gz (99.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_compressor-4.6.0-py3-none-any.whl (96.8 kB view details)

Uploaded Python 3

File details

Details for the file django_compressor-4.6.0.tar.gz.

File metadata

  • Download URL: django_compressor-4.6.0.tar.gz
  • Upload date:
  • Size: 99.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for django_compressor-4.6.0.tar.gz
Algorithm Hash digest
SHA256 c7478feab98f3368780591f9ee28a433350f5277dd28811f7f710f5bc6dff3c0
MD5 7cb34cf1f3fc632ad7b631fb1d1966d9
BLAKE2b-256 a2e4c6d87b1341d744ceafa85eeceb2adabb1c62b795b8207cbc580fb70df8f4

See more details on using hashes here.

File details

Details for the file django_compressor-4.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_compressor-4.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e7b21020a0d86272c5e37000c33accc4ebeb77394a3dd86d775a09aae7aade4
MD5 fd2f83d4d3a21fe38f13d9a64d6f9a10
BLAKE2b-256 d59d9a0ba39f33574994e5b33aea55a68e8fad72b8dd923a82300e4e91774f59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page