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 https://caniusepython3.com/project/django_compressor.svg

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.

Django Compressor is compatible with Django 1.11 and newer.

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, the 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-2.4.1.tar.gz (123.8 kB view details)

Uploaded Source

Built Distribution

django_compressor-2.4.1-py2.py3-none-any.whl (145.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django_compressor-2.4.1.tar.gz
  • Upload date:
  • Size: 123.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for django_compressor-2.4.1.tar.gz
Algorithm Hash digest
SHA256 3358077605c146fdcca5f9eaffb50aa5dbe15f238f8854679115ebf31c0415e0
MD5 f4e8091d4d67dd1348d4519bab3c94eb
BLAKE2b-256 34774352563ad70317ac021ba913c2f8cdb5b10cb35c70885d27f2c83cddff22

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: django_compressor-2.4.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 145.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for django_compressor-2.4.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f8313f59d5e65712fc28787d084fe834997c9dfa92d064a1a3ec3d3366594d04
MD5 63468a311dada59a4a4b8e99c37ef020
BLAKE2b-256 ae7d5cc45560591c1a8b3c180c3fd89975e4cb9d4097dcec6b7736530099f093

See more details on using hashes here.

Provenance

Supported by

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