question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warn when calling precache with a string or without revision property

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jeffposnickcommented, Oct 22, 2019

Ah, so the mention of revision: null helped me find where we talked about this previously: https://github.com/GoogleChrome/workbox/pull/2124

That 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 to precache()/precacheAndRoute(), and like I mentioned, I think it’s a good idea to do that (via console.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.

0reactions
jeffposnickcommented, Jan 13, 2020

Thanks for pointing that out, @brettwillis! I’ll fix that up to switch to revision: null.

Read more comments on GitHub >

github_iconTop Results From Across the Web

workbox-precaching - Chrome Developers
workbox-precaching expects an array of objects with a url and revision property. This array is sometimes referred to as a precache manifest:
Read more >
javascript - Removing __WB_REVISION__ Query String ...
My project is running under very strict rules, and the backend will create unique cache entries for each request with different query strings....
Read more >
ETag - HTTP - MDN Web Docs
The ETag (or entity tag) HTTP response header is an identifier for a specific version of a resource. It lets caches be more...
Read more >
Ember.Engine - 2.13 - Ember API Documentation
The rev is the last property revision of the object when it changed, which you can use to detect if the key value...
Read more >
workbox-9fe249eb.js.map · oldhuhu/drawio - Gitee.com
n * @return {Object} An object with `route` and `params` properties.\n * They are populated if a matching route was found or `undefined`\n...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found