Re: [w3c/ServiceWorker] Add a script version property to the ServiceWorker object (#1387)

So after playing around with this a bit, I'm realizing my original proposal is not going to work. At least not as a way to set a property on a `ServiceWorker` object from the window.

The problem comes if the page is serving content cache-first, so it's running an outdated version of the JavaScript, but a newer version of the service worker is available. Here's how that could play out (note: this example puts the script version in the URL, but the same problem would exist if it were set via a `scriptVersion` configuration option):

- A navigation request returns cached HTML/JS, which registers `sw.js?v=1`
- When the browser requests `sw.js?v=1`, it finds an updated version (v2) but its `scriptURL` property on the registration will still say v1
- The `updatefound` event listener prompts the user to reload to get the latest version of the page.
- When the user reloads the new HTML/JS will register `sw.js?v=2`, which hasn't changed on the server since it was just downloaded, but because the URLs are different, it'll trigger a new install.

I think this means *if* we add any kind of versioning to the `ServiceWorker` object, it'll have to be set either from within the service worker file itself, or automatically assigned by the UA. It can't be set from the window.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1387#issuecomment-459588039

Received on Friday, 1 February 2019 02:59:31 UTC