I want my PWA to periodically update itself while it is running, not waiting for the user to refresh the page (e.g. on iOS 12 it is actually quite hard to trigger page reload of a PWA).
I know there is ServiceWorkerRegistration.update() method, but it's not supported by Safari.
So, are there any workarounds to get my ServiceWorker to self-update without page reload on iOS?
Additional information:
Currently I periodically poll version.json
file in which I put current app's version, pare it, and force a page reload. It works fine, but it requires two page reload to get the new version (this + after the activated event to load the new app's assets).
Here's my current solution, if you need more context: .js#L31
I want my PWA to periodically update itself while it is running, not waiting for the user to refresh the page (e.g. on iOS 12 it is actually quite hard to trigger page reload of a PWA).
I know there is ServiceWorkerRegistration.update() method, but it's not supported by Safari.
So, are there any workarounds to get my ServiceWorker to self-update without page reload on iOS?
Additional information:
Currently I periodically poll version.json
file in which I put current app's version, pare it, and force a page reload. It works fine, but it requires two page reload to get the new version (this + after the activated event to load the new app's assets).
Here's my current solution, if you need more context: https://github./dimaip/calendar/blob/master/app/serviceWorker.js#L31
Share Improve this question edited Jun 12, 2020 at 8:57 Dmitri Pisarev asked Jun 11, 2020 at 15:24 Dmitri PisarevDmitri Pisarev 1,17313 silver badges32 bronze badges 2-
1
Would falling back on
location.reload()
work? – Ken Kinder Commented Jun 11, 2020 at 15:26 - @KenKinder hey, yes, that's basically what I had in mind if I got a definitive NO to this question. – Dmitri Pisarev Commented Jun 11, 2020 at 17:42
1 Answer
Reset to default 8ServiceWorkerRegistration.update()
is supported by all browsers that support service workers, and should acplish what you want.
If you wanted to confirm for yourself that it's actually supported in Safari, try running
reg = await navigator.serviceWorker.ready
reg.update()
in Safari's JS console, with the Network panel open. You should see a request made for your service worker after you run that.