Skip to content

Conversation

blighj
Copy link
Contributor

@blighj blighj commented Aug 9, 2025

Trac ticket number

ticket-27929

Branch description

When collecting static files with ManifestStaticFilesStorage, both hashed and original versions are created by default. This adds a keep_original_files attribute to allow removal of original non-hashed files after processing for production deployments where only hashed versions are needed.

There have already been two PR's on this #17328 by @theumang100 and #16625 by @valleyofblackpanther
This PR is more inspired by whitenoise's approach of keeping a track of which files to delete during processing and then deleting them at the end, though uses a slightly different approach.

It also makes it more convenient to update the ManifestStaticFilesStorage configuration from the already supported OPTIONS keyword of the STORAGES setting.
eg

{
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
        "OPTIONS":  {
            "keep_original_files": False,
            "manifest_name": "secured_through_obscurity_staticfiles.json",
            "manifest_strict": False,
            "support_js_module_import_aggregation": True,
        },
    },
}

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@blighj blighj changed the title Fixed #27929 -- Added keep_original_files option to ManifestFilesMixin. Fixed #27929 -- Added ManifestStaticFilesStorage option to keep/remove original (non-hashed) files after processing Aug 11, 2025
    When collecting static files with ManifestStaticFilesStorage, both hashed and original versions are created by default. This adds a keep_original_files attribute to allow removal of original non-hashed files after processing for production deployments where only hashed versions are needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant