Warn when calling precache with a string or without revision property
See original GitHub issueI’m sure that this was discussed during v5 development, but I’m unable to find the historical issues/PRs with comments about it.
A fairly common issue that we see is developers who pass in string URLs, like '/offline.html'
, that lack versioning info to workbox-precaching
. This is a problem because those URLs will never be updated after being cached for the first time. (This is fine if those URLs do contain versioning info, like /app.1234abcd.js
, since it’s assumed that the contents will never change, so updates aren’t necessary.)
This came up most recently when I took a look at https://github.com/GoogleChrome/web.dev/blob/93694df6ec4874a85975127ce4a1856066e76bf5/src/lib/sw.js#L9
I think what we ended up deciding on is that all of the build tools will produce {url: '/app.1234abcd.js'}
manifest entries, and that we’d very explicitly warn folks who passed in strings in v5 that they need to make sure those URL strings included versioning information, or else dire things would happen. (I’d actually be in favor of doing this in production builds, unlike most of our other warnings that only trigger in dev builds.) And then potentially deprecate passing in strings in v6.
But… I can’t find any code in PrecacheController
that actually does that.
@philipwalton, is my recollection on that decision accurate? If so, I think we just forgot to add in that extra warning message, and we still have time to do that before the final v5 release.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
Ah, so the mention of
revision: null
helped me find where we talked about this previously: https://github.com/GoogleChrome/workbox/pull/2124That was just in the context of using
additionalManifestEntries
in the build tools, and we did add in a build-time requirement there.So this issue could track implementing the same check at runtime inside the service worker, to prevent developers from finding the
workbox-precaching
module and using it directly by passing in unversioned URLs.The runtime check would log a warning whenever a string or an object without a
revision
property are passed in toprecache()
/precacheAndRoute()
, and like I mentioned, I think it’s a good idea to do that (viaconsole.warn()
) even in the production builds.And then in v6, we can stop supporting passing in a string or an object without a
revision
property.Thanks for pointing that out, @brettwillis! I’ll fix that up to switch to
revision: null
.