Skip to content

Instantly share code, notes, and snippets.

@steph-crown
Last active October 28, 2024 14:59
Show Gist options
  • 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