Saturday, 4 January 2020

When should a service worker self destruct?

I found this repo describing HOW to destroy a service worker. But I didn't find any resources describing WHEN a worker should destroy/uninstall/unregister itself.

When I develop websites, I often use port 8080. I can be working on site X that has a service worker, then work on site Y that doesn't have a service worker but the original and now incorrect service worker persists.

The logic for a service worker deciding to uninstall itself is a bit tricky because we want to:

  • Allow the service worker to work offline.
  • Allow the service worker to survive a captive wifi portal.
  • Detect the browser is online but this site should not have a service worker, or that the service worker should be a different one.

Is there a standard mechanism or convention around this?



from When should a service worker self destruct?

No comments:

Post a Comment