Last active
June 10, 2017 07:23
-
-
Save KaySchneider/ecdb98d24e6db6c3ca18879aac31cf2f to your computer and use it in GitHub Desktop.
Service worker for progressive web app tutorial: http://blog.yakisch.com/post/159010205729/progressive-web-apps-teil-2-service-worker
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
var cacheName = 'notenrechnerjk829829328931'; | |
var filesToCache = [ | |
'/notenRechner/', | |
'/notenRechner/manifest.json', | |
'/notenRechner/index.html', | |
'/notenRechner/libs/material.min.js', | |
'/notenRechner/libs/material.min.css', | |
'/notenRechner/js/app.js', | |
'/notenRechner/styles/main.css', | |
]; | |
self.addEventListener('install', function(e) { | |
e.waitUntil( | |
caches.open(cacheName).then(function(cache) { | |
console.log('[ServiceWorker] Caching app shell'); | |
return cache.addAll(filesToCache); | |
}) | |
); | |
}); | |
self.addEventListener('fetch', function(e) { | |
e.respondWith( | |
caches.match(e.request).then(function(response) { | |
return response || fetch(e.request); | |
}) | |
); | |
}); | |
self.addEventListener('activate', function(e) { | |
e.waitUntil( | |
caches.keys().then(function(keyList) { | |
return Promise.all(keyList.map(function(key) { | |
if (key !== cacheName) { | |
console.log('[ServiceWorker] Removing old cache', key); | |
return caches.delete(key); | |
} | |
})); | |
}) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment