Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save helloguille/466e61a9b5ea8d6632542a4b41ce7192 to your computer and use it in GitHub Desktop.
Save helloguille/466e61a9b5ea8d6632542a4b41ce7192 to your computer and use it in GitHub Desktop.
CODE IN PAGE:
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
console.log('ServiceWorker registration failed: ', err);
});
});
SW.JS
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log("(sw) will call cache.addAll()");
/*
Include only internal URL, other like Font awesome and fonts are not really required
*/
return cache.addAll([
'/worngfile.png'
]).then(function() {
console.log("(sw) cache.addAll done");
});
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment