Prevent unnecessary downloads of unchanged assets#57
Merged
Conversation
added 2 commits
September 1, 2020 12:31
This cache-busting strategy is more realistic and less aggressive, because it only forces the browser to download a new asset bundle when an asset in that bundle changes. For example, using the standard assets.version/timestamp strategy, every time the CSS changes, all the JS will also be re-downloaded. With this new strategy, when the CSS changes, only the CSS gets re-downloaded.
Contributor
|
Tested, and works as expected and defined. Only thing of note is while watching it seemed to take a really long time to compile on a javascript change. |
Contributor
Author
|
@rbhensley this seems to happen on Wrote up #60 to look into this. |
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.
Testing
Switch to the branch and watch assets for changes as you normally would:
Make some changes to JS/CSS files and note that the contents of
scripts.versionandstyles.versionchange, and correspond to the query string being served for the<script>and<link>tags for those assets. Specifically, saving a change and then undoing that change should result in the same hash.Background
This introduces a
useHashoption to the custom WebpackAssetsVersionPluginwhich is responsible for writing to theassets.versionfile, or any other version file you configure. This is the file that Conifer'sSite::enqueue_script()andSite::enqueue_style()methods read from to do cache-busting.The new plugin option tells the plugin to write the hash of the bundled asset's content (for example, a hash of all the JS it just compiled) to the version file instead of a simple timestamp. Passing this option has the effect of busting the browser cache only when the contents of the bundle change.
This PR also separates the CSS and JS bundles out onto their own asset version "channels," i.e. they get cached (and cache-busted) independently of each other. For example, when CSS changes, the browser will only re-download the new CSS files and JS will stay cached.