If you delete a service worker when users already have it installed, you can cause problems for your users.
The installed (orphaned) service worker still has control of your site on the user's device. When the locally cached page is rendered, it will try to register the no-longer-existing service worker. But it will fail. Any stale content that was pre-cached by the orphaned service worker won't get updated.
The fix: When you first deploy a service worker, you can include protection against future orphaning. Add a check to ensure registration succeeds. If registration fails, unregister any installed service workers.
Open your browsers developer tools. Refresh the page multiple times and you should see alternating registrations and unregistrations.
Look at the deletion-safe registration source.
Made by @abraham and @pblatteier with Glitch!