NekR / offline-plugin

Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
MIT License
4.52k stars 295 forks source link

SW only updated after all page instances closed #373

Closed wclr closed 6 years ago

wclr commented 6 years ago

I use default cache-first strategy.

1) After new update deployed client reloads the page and loads old version from cache, in the console I see: image

Also runtime update ready fires.

2) Then I reload the page. Runtime update ready fires again. But I still see the old (previous) version. Then I can reload page multiple times it still not get updated.

3) I close all the tabs (one or if where opened multiple) of this page, and open it again. And now I see updated (the latest) version. In the console I see this time: image

This behaviour I see on windows chrome/firefox.

On iOs (11.3, where SW is available already) in Safari, site seems to update as expected (on the first reload after update had been downloaded).

The metadata of the site you may see in my other issue https://github.com/NekR/offline-plugin/issues/369.

sw.js has no-store and no-cache headers

wclr commented 6 years ago

I have fixed that by calling applyUpdate() in onUpdateReady event handler.

Is this implied workflow/lifecycle? I mean in docs it is said that if you want to you may call it, but without calling it works the strange way I described and on iOs (11.3 with SW enabled) in web app (full screen) mode offline update doesn't work at all, though as I mentioned it works ok in Safari (not full screen).

NekR commented 6 years ago

@whitecolor the flow described in the first comment correct and that's how it works (ServiceWorker), see this doc: https://github.com/NekR/offline-plugin/blob/master/docs/updates.md

I mean in docs it is said that if you want to you may call it, but without calling it works the strange way I described

It works as ServiceWorker supposed to work (and works by default). If you want, to improve it, you may use applyUpdate(), which you do.

About iOS 11.3. No idea what happens there. Maybe it doesn't start ServiceWorker there and starts AppCache, that's why you see different flow. Or maybe they simply have bugs, as they always do. That's Safari, not a surprise. Standalone mode on iOS is even worse, total disaster. No surprise it doesn't work there.

It will work in Safari as it should when they will follow the spec and fix all their ServiceWorker issues.