awesome-python/website/data/category_intros/web-asset-management.md
Vinta Chen 8b04838903
docs: add web asset management category intro
The page had no intro, so readers got no pick between django-storages and Django Compressor.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-27 06:26:25 +08:00

2.8 KiB

Django serves static files only in development, but django-storages puts them and user uploads on S3 or other clouds. Django Compressor bundles CSS and JS.

How to choose:

  • Static files and user uploads on S3, Google Cloud Storage, or Azure: django-storages
  • CSS and JavaScript combined and minified from your templates: Django Compressor

django-storages is a collection of storage backends for Django: Amazon S3, Google Cloud Storage, Azure Storage, and more. Install the extra for your backend, like django-storages[s3]. Configure it through Django's STORAGES setting, with the backend's settings under OPTIONS. The default key stores user uploads, and a staticfiles key has collectstatic put your static files on S3 too. Django's security docs say to serve user uploads from a separate domain, not a subdomain of your site.

Django Compressor processes, combines, and minifies the CSS and JavaScript in your Django templates into cacheable static files. It also supports compilers like Sass and LESS. Its maintainer sees it as an alternative for people who don't want to keep up with JavaScript build tools and want one easy setup for development and production. Add compressor to INSTALLED_APPS and its finder to STATICFILES_FINDERS. Then wrap your <link> and <script> tags in {% compress css %} and {% compress js %} blocks. In production, its docs strongly recommend a real cache backend. On several servers, or with compressed files on a CDN, use offline compression: set COMPRESS_OFFLINE and run manage.py compress when you deploy. Jinja2 templates work through its extension.

django-storages and Django Compressor work together. Django Compressor's docs point to django-storages for pushing compressed files to S3, and it saves them to the storage you define under the compressor alias in STORAGES.