Re: [w3c/ServiceWorker] Immediate Service Worker (#1389)

I am aware of the `ServiceWorkerGlobalScope.skipWaiting()` method, but I am discouraged by two points:

1. The new v2 Service Worker will activate and delete the old v1 Cache while a v1 tab is still open.
2. The worst thing about blindly calling skipWaiting() is that it appears to work perfectly at first, but it results in bugs in production that are difficult to understand and reproduce.

Source: https://redfin.engineering/how-to-fix-the-refresh-button-when-using-service-workers-a8e27af6df68 (Approach 1)

Let's imagine a single page app loading some resource mapping initially (json in the html header) and via XHR requesting these resources (images) on demand. Version 2 requires different resources, so the mapping is different. If this v2 is opened in the new tab and waiting is skipped, the cache for v1 is deleted. That initially loaded mapping in v1 is still same (until refreshing the page), it still expects all resources in place, but they do not exist neither in cache nor on the server. The v1 gets broken unexpectedly.

In my 'immediate' approach I am trying to treat multiple SW versions separately per tab. Newer tab displays newer version while older one is still functional. In an ideal case the browser could display some alert on that old tab encouraging user to reload the page (already discussed in #1247).

While this approach covers rather a corner case (multiple tabs with the same app, but different versions), this could eliminate various workarounds, see aforementioned article.


-- 
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/1389#issuecomment-465317611

Received on Tuesday, 19 February 2019 21:29:04 UTC