Skip to content

Commit

Permalink
remove redundant service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
p-mbanugo committed Feb 14, 2018
1 parent 2af0a4b commit d660f5e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 153 deletions.
2 changes: 1 addition & 1 deletion public/sw.js
Expand Up @@ -48,7 +48,7 @@ const fileManifest = [
},
{
"url": "manifest.json",
"revision": "cfada03439f24ccdb59dae8d4f6370d1"
"revision": "f4850783fae8b37f26db86712c8b4505"
},
{
"url": "resources/dialog-polyfill/dialog-polyfill.css",
Expand Down
140 changes: 30 additions & 110 deletions public/sw.old.js
@@ -1,122 +1,42 @@
importScripts("/resources/sw-toolbox.js");

const version = "0.4";
const CACHE_NAME = "cache-v1";

const assetToCache = [
"/index.html",
"/",
"/history.html",
"/manifest.json",
"/resources/mdl/material.indigo-pink.min.css",
"/resources/mdl/material.min.js",
"/resources/mdl/MaterialIcons-Regular.woff2",
"/resources/mdl/material-icons.css",
"/css/style.css",
"/resources/dialog-polyfill/dialog-polyfill.js",
"/resources/dialog-polyfill/dialog-polyfill.css",
"/resources/system.js",
"/js/transpiled/index.js",
"/js/transpiled/history.js",
"/js/transpiled/shared.js",
"/hoodie/client.js"
];

self.addEventListener("install", function(event) {
event.waitUntil(
caches
.open(version)
.open(CACHE_NAME)
.then(function(cache) {
return cache.addAll([
"/index.html",
"/",
"/history.html",
"/manifest.json",
"/resources/mdl/material.indigo-pink.min.css",
"/resources/mdl/material.min.js",
"/resources/mdl/MaterialIcons-Regular.woff2",
"/resources/mdl/material-icons.css",
"/css/style.css",
"/resources/dialog-polyfill/dialog-polyfill.js",
"/resources/dialog-polyfill/dialog-polyfill.css",
"/resources/system.js",
"/js/transpiled/index.js",
"/js/transpiled/history.js",
"/js/transpiled/shared.js",
"/hoodie/client.js"
]);
})
.then(r => {
console.log("SW skipping wait");
self.skipWaiting();
console.log("SW Installed");
return r;
return cache.addAll(assetToCache);
})
.catch(console.error)
);
});

self.addEventListener("activate", function(event) {
console.log("SW activating ..");
event.waitUntil(
caches
.keys()
.then(function(keys) {
return Promise.all(
keys
.filter(function(key) {
return key !== version;
})
.map(function(key) {
return caches.delete(key);
})
);
})
.then(r => {
console.log("SW claiming");
self.clients.claim();
console.log("SW activated => version ", version);
console.log(r);
return r;
})
.catch(console.error)
self.addEventListener("fetch", function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
if (response) {
return response;
}
return fetch(event.request);
})
);
});

toolbox.router.get("/hoodie/client.js", toolbox.cacheFirst, {
cache: {
name: version,
maxAgeSeconds: 60 * 60 * 24 * 365
}
});

//toolbox.router.get("/hoodie/*", toolbox.networkOnly);//include a timer to allow quick XHR request termination when offline?

toolbox.router.get("/", toolbox.cacheFirst, {
cache: {
name: version,
maxAgeSeconds: 60 * 60 * 24 * 365
}
});

toolbox.router.get("/index.html", toolbox.cacheFirst, {
cache: {
name: version,
maxAgeSeconds: 60 * 60 * 24 * 365
}
});

toolbox.router.get("/history.html", toolbox.cacheFirst, {
cache: {
name: version,
maxAgeSeconds: 60 * 60 * 24 * 365
}
});

toolbox.router.get("/manifest.json", toolbox.cacheFirst, {
cache: {
name: version,
maxAgeSeconds: 60 * 60 * 24 * 365
}
});

toolbox.router.get("/resources/*", toolbox.cacheFirst, {
cache: {
name: version,
maxAgeSeconds: 60 * 60 * 24 * 365
}
});

toolbox.router.get("/css/*", toolbox.cacheFirst, {
cache: {
name: version,
maxAgeSeconds: 60 * 60 * 24 * 365
}
});

toolbox.router.get("/js/*", toolbox.cacheFirst, {
cache: {
name: version,
maxAgeSeconds: 60 * 60 * 24 * 365
}
});
42 changes: 0 additions & 42 deletions public/sw1.js

This file was deleted.

0 comments on commit d660f5e

Please sign in to comment.