Django Compressor

Combine, compile, and minify inline and linked JavaScript and CSS in Django templates into cacheable static files.

Library
PyPI
v4.6.0
2,870stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
62/100Good
Development Activity52
Maintenance16
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture84
Code Quality82
Innovation74
Learning Curve72

Django Compressor is a Django application that processes, combines, and minifies the JavaScript and CSS referenced in your templates, turning them into content-hashed, cacheable static files. You wrap markup in {% compress js/css %} tags and it parses the enclosed assets, runs them through configurable compilers and filters, and outputs optimized <script>/<link> tags.

Because output filenames are derived from content, the generated files can be served with far-future expiration headers without risking stale caches. Compression can happen at request time or be pre-generated offline with the manage.py compress management command.

What You Get

  • {% compress js %} / {% compress css %} template tags that bundle and minify enclosed assets
  • A manage.py compress management command for offline/precompiled compression
  • Built-in filters for YUI, yUglify, Closure Compiler, JSmin, and csscompressor
  • Support for SASS, LESS, and CoffeeScript compilers as processing steps
  • Pluggable HTML parsers (lxml, BeautifulSoup, html5lib) and extensible custom filters

Common Use Cases

  • Bundling and minifying a Django site’s CSS and JS for production
  • Compiling SASS/LESS/CoffeeScript sources during asset compression
  • Precompressing assets offline so requests never pay the compile cost
  • Serving content-hashed static files with far-future cache headers

Under The Hood

Architecture The compressor package parses the HTML between {% compress %} tags (via pluggable parsers in compressor/parser), classifies nodes as JS or CSS through js.py/css.py built on a shared base.py Compressor, runs each through an ordered chain of filters/compilers from compressor/filters, and writes content-hashed output resolved through finders.py and cached via cache.py. A management command exposes the same pipeline for offline runs. Tech Stack Pure Python targeting Django, with optional lxml for fast HTML parsing (falling back to the stdlib parser, BeautifulSoup, or html5lib) and shell-outs to external compilers/minifiers (SASS, LESS, Closure, YUI) plus pure-Python filters like JSmin and csscompressor. Code Quality The codebase is modular and long-established, with a documented Sphinx site, a tox matrix across Django/Python versions, and Codecov-tracked tests; the main weakness flagged is infrequent recent maintenance. API Design The primary interface is declarative template tags with settings-based configuration, so basic use needs no Python code, while extensibility comes through well-defined filter and parser base classes for custom processing steps.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search