Added service worker

This commit is contained in:
Marcus Noble
2017-10-11 21:25:20 +01:00
parent 21ba182d67
commit 628c620093
2 changed files with 25 additions and 0 deletions

18
src/service-worker.js Normal file
View File

@@ -0,0 +1,18 @@
var CACHE = 'v1';
self.addEventListener('fetch', function(event) {
event.respondWith(fetchAndCache(event));
});
function fetchAndCache(event) {
return caches.open(CACHE).then(function (cache) {
return fetch(event.request)
.then(function(response) {
cache.put(event.request, response.clone());
return response;
})
.catch(function() {
return cache.match(event.request);
});
});
}