Skip to content

Instantly share code, notes, and snippets.

@kaknut
Created June 5, 2019 10:05
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/efc000a8761b7d01b64fcf1f0ab0686c to your computer and use it in GitHub Desktop.
Save kaknut/efc000a8761b7d01b64fcf1f0ab0686c 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
// Check compatibility for the browser we're running this in
if ("serviceWorker" in navigator) {
if (navigator.serviceWorker.controller) {
console.log("NutPanda: active service worker found, no need to register");
} else {
// Register the service worker
navigator.serviceWorker
.register("sw.js", {
scope: "./"
})
.then(function (reg) {
console.log("NutPanda 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