Saturday, 4 August 2018

Register service worker after hard refresh

Whenever the web application with service worker is reloaded after hard refresh (Ctrl + F5 for Chrome, for example), the service worker is unable to register afterwards.

According to the documentation at W3C

Note: navigator.serviceWorker.controller returns null if the request is a force refresh (shift+refresh). The ServiceWorker objects returned from this attribute getter that represent the same service worker are the same objects.

So, the question is: is it really impossible to register service worker right after the hard refresh is performed? I am checking the existence of the service worker with the navigator.serviceWorker.controller. Please see the attached GIF which shows interaction with the https://googlechrome.github.io/samples/service-worker/basic/ page

enter image description here



from Register service worker after hard refresh

No comments:

Post a Comment