Skip to main content

Enhanced ManifestStaticFilesStorage for Django

Project description

Django ManifestStaticFiles Enhanced

Enhanced ManifestStaticFilesStorage for Django.

AI tools were used for creation of this package

  • Tool(s) used: Claude Code
  • What it was used for: Used for building initial versions of all features and for initial versions of original tests.

Features

This package includes several improvements to Django's ManifestStaticFilesStorage:

  • ticket_27929: keep_original_files option to control whether original files are deleted after hashing
  • ticket_21080: CSS lexer for better URL parsing in CSS files
  • ticket_34322: JsLex for ES module support in JavaScript files
  • ticket_28200: Optimized storage to avoid unnecessary file operations for unchanged files

Compatibility

  • Django: 4.2, 5.0, 5.1, 5.2
  • Python: 3.9, 3.10, 3.11, 3.12, 3.13

Installation

pip install django-manifeststaticfiles-enhanced

Usage

Basic Usage

Replace Django's default ManifestStaticFilesStorage with the enhanced version using the STORAGES setting:

# settings.py
STORAGES = {
    "staticfiles": {
        "BACKEND": "django_manifeststaticfiles_enhanced.storage.EnhancedManifestStaticFilesStorage",
    },
}

Configuration Options

keep_original_files (ticket_27929)

Control whether original files are kept after hashing:

# settings.py - Keep original files (default)
STORAGES = {
    "staticfiles": {
        "BACKEND": "django_manifeststaticfiles_enhanced.storage.EnhancedManifestStaticFilesStorage",
        "OPTIONS": {
            "keep_original_files": True,  # Default
        },
    },
}

# Or delete original files to save space
STORAGES = {
    "staticfiles": {
        "BACKEND": "django_manifeststaticfiles_enhanced.storage.EnhancedManifestStaticFilesStorage",
        "OPTIONS": {
            "keep_original_files": False,
        },
    },
}

JavaScript Module Support (ticket_34322)

Disable ES module import/export processing:

# settings.py
STORAGES = {
    "staticfiles": {
        "BACKEND": "django_manifeststaticfiles_enhanced.storage.EnhancedManifestStaticFilesStorage",
        "OPTIONS": {
            "support_js_module_import_aggregation": False,
        },
    },
}

Easy access to existing options

Disable manifest_strict

# settings.py
STORAGES = {
    "staticfiles": {
        "BACKEND": "django_manifeststaticfiles_enhanced.storage.EnhancedManifestStaticFilesStorage",
        "OPTIONS": {
            "manifest_strict": False,
        },
    },
}

Also available:

Feature Details

CSS Processing Improvements (ticket_21080)

CSS URL processing uses a proper lexer instead of regex, providing:

  • Ignores url's in comments
  • More reliable URL extraction
  • Wider @import support

File Operation Optimization (ticket_28200)

Reduces unnecessary file operations during collectstatic:

  • Avoids recreating files that haven't changed
  • Checks file existence before deletion

JavaScript Module Support (ticket_34322)

Enabled by default:

  • Processes ES6 import/export statements
  • Handles dynamic imports
  • Updates module paths to hashed versions

Example JavaScript that gets processed:

// Before processing
import { Component } from './component.js';
export { utils } from './utils.js';

// After processing (with hashing)
import { Component } from './component.abc123.js';
export { utils } from './utils.def456.js';

Option to not move the origianl asset to your static folder (ticket_27929)

Control file cleanup behavior:

# Keep original files (default)
keep_original_files = True
# Results in: style.css + style.abc123.css

# Delete original files
keep_original_files = False  
# Results in: style.abc123.css only

Running Tests

# Install development dependencies
pip install -e .[dev]

# Run tests
python tests/runtests.py

# Or run specific test modules
python tests/runtests.py staticfiles_tests.test_storage

Migration from Django's ManifestStaticFilesStorage

This package is designed as a drop-in replacement:

  1. Install the package
  2. Update your STORAGES setting
  3. Run python manage.py collectstatic as usual

All existing functionality remains the same, with additional features available through configuration options.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the BSD 3-Clause License - the same license as Django.

Changelog

0.2.0

  • Performence improvements
  • Improved exception messages
  • Fixed issue with js dynamic imports that include template literals
  • Improved handling of soucerMapURLs

0.1.0 (Initial Release)

  • Includes keep_original_files option (ticket_27929)
  • Includes CSS lexer improvements (ticket_21080)
  • Includes file operation optimizations (ticket_28200)
  • Includes JavaScript module support (ticket_34322)
  • Added comprehensive test suite
  • Support for Django 4.2+

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_manifeststaticfiles_enhanced-0.2.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file django_manifeststaticfiles_enhanced-0.2.1.tar.gz.

File metadata

File hashes

Hashes for django_manifeststaticfiles_enhanced-0.2.1.tar.gz
Algorithm Hash digest
SHA256 990ffa2cd1548d8c637c45c8da9f820677fb4178c714b49f9bb20100e8dd19a0
MD5 ea80d326054bcb3759936fba4da78e2a
BLAKE2b-256 9957c42bbde3f6e743fe92ee31822a9ce91644e063d2a20fd2c2f1865cb472f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_manifeststaticfiles_enhanced-0.2.1.tar.gz:

Publisher: pypi-release.yml on blighj/django-manifeststaticfiles-enhanced

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_manifeststaticfiles_enhanced-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_manifeststaticfiles_enhanced-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3fb6bc6af027f829ff53bfb6798628f11fd5431750f8eb38c71a88ce4376b781
MD5 b411992fb09d9e6b9b792e786f9ea276
BLAKE2b-256 e431af6c6e591c652cc73fe954da9501c1be30eb27f7676c687e559bb70e3dcb

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_manifeststaticfiles_enhanced-0.2.1-py3-none-any.whl:

Publisher: pypi-release.yml on blighj/django-manifeststaticfiles-enhanced

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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