Skip to content

Instantly share code, notes, and snippets.

@jgw96
Last active December 15, 2017 17:32
Show Gist options
  • Save jgw96/a371575037b605a7f85e0e75eafb7a58 to your computer and use it in GitHub Desktop.
Save jgw96/a371575037b605a7f85e0e75eafb7a58 to your computer and use it in GitHub Desktop.
if ('serviceWorker' in navigator && location.protocol !== 'file:') {
window.addEventListener('load', function(){
navigator.serviceWorker.register('/sw.js')
.then(function(reg) {
reg.addEventListener('updatefound', function() {
const toast = document.createElement('div');
toast.innerHTML = '<button>Update available</button>';
document.body.appendChild(toast);
})
})
.catch(function(err) { console.log('service worker error', err) });
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment