Skip to content

Instantly share code, notes, and snippets.

@steph-crown
Last active January 28, 2022 12:19
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 steph-crown/bff38c0e1b14a3a5060aaabc77456081 to your computer and use it in GitHub Desktop.
Save steph-crown/bff38c0e1b14a3a5060aaabc77456081 to your computer and use it in GitHub Desktop.
A script to register a service worker
// Checks if we can use serviceWorker.
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("sw.js")
.then((registration) => {
// The registration wass successful
console.log("Service worker registered");
console.log(registration);
})
.catch((err) => {
// The registration failed
console.log("Sercvice worker registration failed");
console.error(err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment