Code-snippets and guides on removing ServiceWorker from a websiste.
Switch branches/tags
Nothing to show
Clone or download
NekR Merge pull request #2 from gnhuy91/patch-1
Fix typo for npm pkg name
Latest commit 1b2c693 Nov 23, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
packages Fix typo Nov 23, 2017
tests/service-worker Init Nov 20, 2017
.gitignore Init Nov 20, 2017
LICENSE.md Init Nov 20, 2017
README.md Fix links Nov 21, 2017
package.json Add README, Gatsby and webpack packages Nov 21, 2017

README.md

Self-destroying ServiceWorker

Code-snippets and guides on removing ServiceWorker from a websiste.

Motivation

ServiceWorker is more and more often used in websites development. It’s being added to popular tools and libraries. Sometimes, it might be used unintentionally (generated by a pre-configured tool automatically) or for experimental purposes. This leads to a situation where ServiceWorker needs to be removed.

Read more on Medium

How to use

  1. Remove everything about your previous ServiceWorker (registration/uninstallation code, ServiceWorker file)
  2. Create a file with the same name as your previous ServiceWorker and put it in the same place where your previous ServiceWorker was
  3. Put following code into the file:
self.addEventListener('install', function(e) {
  self.skipWaiting();
});

self.addEventListener('activate', function(e) {
  self.registration.unregister()
    .then(function() {
      return self.clients.matchAll();
    })
    .then(function(clients) {
      clients.forEach(client => client.navigate(client.url))
    });
});
  1. Deploy your project! 🎉

With webpack | With Gatsby

License

MIT