Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Created June 29, 2019 17:28
Show Gist options
  • Save indreklasn/0718de3470383e38c5266637933ad1e1 to your computer and use it in GitHub Desktop.
Save indreklasn/0718de3470383e38c5266637933ad1e1 to your computer and use it in GitHub Desktop.
if ('serviceWorker' in navigator) {
// attach event listener on page l aod
window.addEventListener('load', () => {
// register serviceWorker withthe [sw.js] file
navigator.serviceWorker.register('/sw.js').then(registration => {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment