Added Django Middleware that Delays Traversal of Static Root until Requested#275
Open
thenewguy wants to merge 11 commits intoevansd:mainfrom
Open
Added Django Middleware that Delays Traversal of Static Root until Requested#275thenewguy wants to merge 11 commits intoevansd:mainfrom
thenewguy wants to merge 11 commits intoevansd:mainfrom
Conversation
Author
|
Question: Would this make sense as the default when the configured storage is a subclass of |
Author
|
@evansd thoughts on merging? it has been working well for me |
Archmonger
suggested changes
Nov 20, 2021
| return None | ||
|
|
||
|
|
||
| class LazyWhiteNoiseMiddleware(WhiteNoiseMiddleware): |
Contributor
There was a problem hiding this comment.
I would personally recommend implementing this feature directly into the original middleware class, and then have it toggleable by a settings.py:WHITENOISE_LAZY value.
I'd also like to point out I agree with your idea on defaulting this to on with ManifestStaticFilesStorage.
5 tasks
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added an additional middleware for Django users that avoids the problems described #263 by constructing the file cache for the static root as files are requested.
WHITENOISE_ROOTis not delayed as it is documented asdon’t use this for the bulk of your static files. Files from finders are also not delayed as this is documented mainly for development and I've assumed its use in production would be fast orcollectstaticwould be used during the build phase.If the configured static storage is a subclass of
ManifestStaticFilesStoragethe middleware makes use ofstaticfiles_storage.hashed_filesto know which files are supposed to exist (avoids accessing the disk to retrieve unknown files) and uses theWHITENOISE_KEEP_ONLY_HASHED_FILESsetting to determine if it should serve unhashed files.