Add support for long-term caching of files with content-hashed filenames #190
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.
Would this be useful to anyone else?
ETags are great but still require an If-None-Match/304 Not Modified request/response cycle. Tools like webpack are often configured to produce static assets with content-hashed filenames. The filename contains a hash of the file content, so when the content changes, the filename changes. For example, Create React App produces (via webpack) filenames like this:
/static/js/main.54d5d5d6.js
.This pull request adds the boolean
--hash
option which enables detection of content-hashed filenames and serves the files with a max-age of 365 days. It also adds the--regexp
option which can be used to change the default RegExp. The default RegExp matches the hash format used by Create React App.https://webpack.js.org/guides/caching/#components/sidebar/sidebar.jsx