Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify interaction between WHITENOISE_KEEP_ONLY_HASHED_FILES and WHITENOISE_ROOT #489

Open
PeterJCLaw opened this issue Apr 12, 2023 · 2 comments

Comments

@PeterJCLaw
Copy link
Contributor

Description

The docs for WHITENOISE_KEEP_ONLY_HASHED_FILES indicate that it can be used to keep only hashed versions of files, which is useful for reducing the size of static files that need to be included in e.g: a Docker image or uploaded to a CDN. This sounds like it's potentially very useful, both for storage costs and build times.

However it's not clear how to use this together with WHITENOISE_ROOT, where you typically do want the non-hashed filenames (though only for a very small number of files).

Is there something in Whitenoise which can translate from the non-hashed names to the hashed names, so that at runtime both are served? Or are these two options incompatible?

Is there a way to use these together for most files, but then to keep the plain filenames around for those in WHITENOISE_ROOT? (Given the small number and likely small size of the latter, maintaining the duplication here feels reasonable).

@evansd
Copy link
Owner

evansd commented Apr 12, 2023

The WHITENOISE_KEEP_ONLY_HASHED_FILES setting only applies to files which pass through Django's staticfiles pipeline i.e. discovered by the various STATICFILES_FINDERS and collected into STATIC_ROOT. Django takes care of mapping from the original names to the hashed names using the static template tag.

Files in WHITENOISE_ROOT exist outside of Django's staticfiles pipeline and so are unaffected by this setting.

@PeterJCLaw
Copy link
Contributor Author

Files in WHITENOISE_ROOT exist outside of Django's staticfiles pipeline and so are unaffected by this setting.

Ah, I see. I'd not realised that that was the expectation, though that explains how these could work together.
Our setup has a directory within the staticfiles which contains the files we want in the root and which is thus referenced by WHITENOISE_ROOT.

I'm not actually sure why our setup is like that, though I know it pre-dates our use of Whitenoise. I'm guessing it does mean we have a single pipeline for all frontend/static files, which is potentially useful in keeping it simple.

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

No branches or pull requests

2 participants