Better working serviceworker and message to enduser

This commit is contained in:
Kasper Rynning-Tønnesen
2016-08-16 10:55:37 +02:00
parent 70576ce0c9
commit 63f6e19fc0
2 changed files with 30 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,8 @@
var version = 'v3.0'; var version = 'v3.2';
var CACHE_FILES = [ var CACHE_FILES = [
'/offline.html', '/offline.html',
'/manifest.json',
'/static/images/favicon.png'
]; ];
self.addEventListener("install", function(event) { self.addEventListener("install", function(event) {
@@ -94,9 +96,23 @@ self.addEventListener('fetch', event => {
// If fetch() returns a valid HTTP response with an response code in the 4xx or 5xx // If fetch() returns a valid HTTP response with an response code in the 4xx or 5xx
// range, the catch() will NOT be called. If you need custom handling for 4xx or 5xx // range, the catch() will NOT be called. If you need custom handling for 4xx or 5xx
// errors, see https://github.com/GoogleChrome/samples/tree/gh-pages/service-worker/fallback-response // errors, see https://github.com/GoogleChrome/samples/tree/gh-pages/service-worker/fallback-response
return caches.open(version + "::zoff").then(function(cache) { if(event.request.url.includes('manifest.json')){
return cache.match("/offline.html"); return caches.open(version + "::zoff").then(function(cache) {
}); return cache.match("/manifest.json");
});
} else if (event.request.url.includes('favicon')) {
return caches.open(version + "::zoff").then(function(cache) {
return cache.match("/static/images/favicon.png");
});
} else if (event.request.url.includes('service-worker')) {
return caches.open(version + "::zoff").then(function(cache) {
return cache.match("/service-worker.js");
});
} else {
return caches.open(version + "::zoff").then(function(cache) {
return cache.match("/offline.html");
});
}
}) })
); );
} }