Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update ServiceWorker without page reload on Safari

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, compare 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.com/dimaip/calendar/blob/master/app/serviceWorker.js#L31

like image 911
Dmitri Pisarev Avatar asked Jan 31 '26 05:01

Dmitri Pisarev


1 Answers

ServiceWorkerRegistration.update() is supported by all browsers that support service workers, and should accomplish 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.

like image 149
Jeff Posnick Avatar answered Feb 02 '26 17:02

Jeff Posnick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!