Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chinhvo/e56b2a869715e07ec6a9046d47d9fa92 to your computer and use it in GitHub Desktop.
Save chinhvo/e56b2a869715e07ec6a9046d47d9fa92 to your computer and use it in GitHub Desktop.
Register a Service Worker
<script>
// Register the service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment