Skip to main content
CI build status Coverage PyPI Version License

A modern Django package for minifying and compressing static files during collectstatic with minimal configuration.

Features

  • CSS/JS Minification: Uses rjsmin and rcssmin for fast minification

  • Dual Compression: Gzip and Brotli compression support

  • Django Integration: Seamless integration with Django’s static file system

  • Selective Processing: Only processes appropriate file types

  • Minified Filename Format: Preserves Django’s hash and adds .min before the extension: name.{hash}.min.ext. This allows precompressed files to be properly served as name.{hash}.min.ext.gz and name.{hash}.min.ext.br.

  • Configurable: Fine-grained control over processing options

Installation

Install from PyPI:

pip install django-minify-compress-staticfiles

Configuration

For Django 4.2+, update your STORAGES setting:

STORAGES = {
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "django_minify_compress_staticfiles.storage.MinicompressStorage",
    },
}

For Django < 4.2, use the legacy setting:

STATICFILES_STORAGE = "django_minify_compress_staticfiles.storage.MinicompressStorage"

Settings

All settings use the MINICOMPRESS_ prefix:

MINICOMPRESS_ENABLED

Enable/disable processing (default: True)

MINICOMPRESS_MINIFY_FILES

Enable CSS/JS minification (default: True)

MINICOMPRESS_GZIP_COMPRESSION

Enable Gzip compression (default: True)

MINICOMPRESS_BROTLI_COMPRESSION

Enable Brotli compression (default: True)

MINICOMPRESS_MIN_FILE_SIZE

Minimum file size for compression in bytes (default: 200)

MINICOMPRESS_MAX_FILE_SIZE

Maximum file size for processing in bytes (default: 10485760, i.e., 10MB) Files larger than this are skipped to prevent memory exhaustion. Adjust based on your available memory and security requirements.

MINICOMPRESS_MAX_FILES_PER_RUN

Maximum number of files to process per collectstatic run (default: 1000) Prevents CPU and memory exhaustion when processing large numbers of files. Increase only if you have verified your system can handle it.

MINICOMPRESS_COMPRESSION_LEVEL_GZIP

Gzip compression level (default: 6, range: 0-9) Level 6 provides a good balance between compression ratio and CPU usage. Higher values (8-9) consume significantly more CPU with diminishing returns. Lower values (0-5) are faster but produce larger compressed files.

MINICOMPRESS_COMPRESSION_LEVEL_BROTLI

Brotli compression quality (default: 4, range: 0-11) Level 4 offers excellent compression with reasonable CPU usage. Higher values (8-11) can cause severe CPU spikes during collectstatic. Lower values (0-3) are faster but less effective compression.

MINICOMPRESS_PRESERVE_COMMENTS

Preserve bang comments in CSS/JS (default: True)

MINICOMPRESS_SUPPORTED_EXTENSIONS

Dictionary of file extensions to process (default: css, js, txt, xml, json, svg, md, rst, html, htm)

MINICOMPRESS_EXCLUDE_PATTERNS

List of glob patterns to exclude from processing (default: ["*.min.*", "*-min.*", "*swagger-ui-*", "*.gz", "*.br", "*.zip"]) Pre-compressed files (e.g., .gz, .br, .zip) are excluded by default to prevent double-compression and security issues.

Usage

Run collectstatic as usual:

python manage.py collectstatic --noinput

The package will automatically:

  • Minify CSS and JavaScript files

  • Create .gz and .br compressed versions

  • Update Django’s manifest with minified file paths

  • Skip already processed files and patterns

Supported File Types

Minification: CSS, JavaScript

Compression: CSS, JS, TXT, XML, JSON, SVG, MD, RST, HTML, HTM

Security and Performance Considerations

The package implements the following safeguards to mitigate common attack vectors and ensure resource stability.

Path Traversal Protection

To prevent directory traversal attacks (e.g., ../etc/passwd), all file paths undergo strict validation. The system enforces a boundary check ensuring no read or write operations occur outside the defined STATIC_ROOT. Any attempt to access parent directories via relative paths is intercepted and blocked.

Memory Exhaustion Prevention

To prevent memory exhaustion, the MAX_FILE_SIZE setting enforces a hard cap on file processing. This prevents the application from attempting to buffer or process excessively large files that could lead to Out-Of-Memory (OOM) errors.

CPU Exhaustion & Resource Throttling

Compression is a CPU-intensive task. To balance throughput with system stability, the default compression levels are tuned for efficiency:

  • Gzip: Level 6

  • Brotli: Level 4

These defaults prevent “CPU pinning” where a single request monopolizes processor cycles.

Compression Bomb Protection

The processor automatically excludes files that are already compressed (e.g., .gz, .br, .zip, .png). This prevents recursive compression cycles and “Zip Bomb” style attacks that could lead to exponential CPU and disk space consumption.

Integrity & Cache Validation

File fingerprinting uses MD5 hashing to match Django’s ManifestFilesMixin algorithm. This ensures consistency between Django’s hashed filenames and our minified filenames, allowing the manifest to correctly map original files to their minified versions.

Dependencies

Required:

  • Django >= 4.2

  • Python >= 3.10

  • brotli >= 1.0.0

  • rjsmin >= 1.2.0

  • rcssmin >= 1.1.0

License

BSD 3-Clause License. See LICENSE file for details.

Contributing

Contributions are welcome! Please see the OpenWISP contributing guidelines for more information.

Support

Release files for django-minify-compress-staticfiles 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-minify-compress-staticfiles 1.1.1
File Size Uploaded
django_minify_compress_staticfiles-1.1.1.tar.gz 30.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-minify-compress-staticfiles 1.1.1
File Interpreter ABI Platform
django_minify_compress_staticfiles-1.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 42.7 kB

Release files / django_minify_compress_staticfiles-1.1.1.tar.gz

Download URL django_minify_compress_staticfiles-1.1.1.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
46a0b478d0c40ac172fa2295b223fbe455b798b1e02638d5d5609d3922b58992
BLAKE2b-256 checksum
How to use checksums
87e41e02211394fc79c7501b52e48bcc5f74635819438a0327f1f1db56e4d37f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 25, 2026.

Transparency log

Release files / django_minify_compress_staticfiles-1.1.1-py2.py3-none-any.whl

Download URL django_minify_compress_staticfiles-1.1.1-py2.py3-none-any.whl
Size 12.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c89c29318944da16c8e45ce3e95527f1f18a0334b2f77448851e652b2381c91e
BLAKE2b-256 checksum
How to use checksums
3107ba68431259a46bdadff9e1a041803bf4143367e36b2815ce5f25d7d06dd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page