Skip to content

Instantly share code, notes, and snippets.

@kaknut
Created June 14, 2019 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaknut/764c23c7b91bf7cca3d13f996acda339 to your computer and use it in GitHub Desktop.
Save kaknut/764c23c7b91bf7cca3d13f996acda339 to your computer and use it in GitHub Desktop.
//Add this below content to your HTML page, or add the js file to your page at the very top to register service worker
if (navigator.serviceWorker.controller) {
console.log('active service worker found, no need to register')
} else {
//Register the ServiceWorker
navigator.serviceWorker.register('/service-worker.js', {
scope: './'
}).then(function(reg) {
console.log('Service worker has been registered for scope:'+ reg.scope);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment