Allow precaching "repair" when using subresource integrity #2921
+149
−31
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.
R: @tropicadri
Fixes #2858
Although unexpected, there are edge cases where the precache might not be in an inconsistent state, most likely due to a developer manually deleting something in DevTools.
When this happens,
workbox-precaching
defaults to falling-back to using a network response (assuming the device is online) when there's a precaching miss. Up until now,workbox-precaching
hasn't attempting to use this network response to repopulate the precache, because there are no guarantees that the network response corresponds to the version of the asset specified in the precache manifest.However, if the precache entry includes an
integrity
property, then subresource integrity guarantees that the response does correspond to the same version of the asset in the manifest. So it should be safe to "repair" the cache with that response.(The
revision
field can't be used for this purpose, because while it's traditionally set to the hash of an asset's content, it could theoretically be set to anything, and it would be much too expensive to calculate the hash of the response body via JavaScript at runtime.)