Skip to content

Instantly share code, notes, and snippets.

Last active Feb 11, 2016
What would you like to do?
Service worker installation steps
//Cache polyfil to support cacheAPI in browsers
//Cache name
var staticCache = "my-static-files";
//Files to cache
var filesToCache = [
//Adding a eventlistener to install event
self.addEventListener("install", function (event) {
//Installation steps
.then(function (cache) {
//[] of files to cache & if any of the file not present compelete `addAll` will fail
return cache.addAll(urlsToCache)
.then(function () {
console.log("Successfully cached.");
.cache(function (error) {
console.log("Failed to cache ", error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment