Skip to main content

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

Project description

https://coveralls.io/repos/django-compressor/django-compressor/badge.png?branch=develop https://pypip.in/v/django_compressor/badge.svg https://pypip.in/d/django_compressor/badge.svg Build Status https://caniusepython3.com/project/django_compressor.svg

Django Compressor combines and compresses linked and inline Javascript or CSS in a Django template 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 a unique name based on their content. Alternatively it can also return the resulting content to 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.

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.

Django Compressor also comes with built-in support for CSS Tidy, YUI CSS and JS compressor, yUglify CSS and JS compressor, the Google’s Closure Compiler, a Python port of Douglas Crockford’s JSmin, a Python port of the YUI CSS Compressor cssmin 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 http://github.com/django-compressor/django-compressor/tarball/develop.

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-1.5.tar.gz (111.3 kB view details)

Uploaded Source

Built Distribution

django_compressor-1.5-py2.py3-none-any.whl (129.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for django_compressor-1.5.tar.gz
Algorithm Hash digest
SHA256 0189fd1dbf87d802f4e4e21ebc9220f29bbb7771b252a958ad6119f61453e22e
MD5 274dd82a45ddd13e111852dd101a5924
BLAKE2b-256 7180ff8aa97f8093da3cc2fbc91cb31586b2d01a8b596018822a7389eed14a23

See more details on using hashes here.

File details

Details for the file django_compressor-1.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_compressor-1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 516866224ec33bf227f79718c0b154debf2967fe249c12d721bbe2c45ecbe34c
MD5 822891c64d8cc3f51e2dede36e8bf750
BLAKE2b-256 99176ba72e44cbd7411819e0a4aca6c6fc8cf41379552e3bb89fd862e775dfaa

See more details on using hashes here.

Supported by

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