Created
June 27, 2016 22:56
-
-
Save helloguille/466e61a9b5ea8d6632542a4b41ce7192 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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