inventur/serviceWorker.js
TLRZ Seyfferth 65bd645dd9 app manifest
2018-01-14 17:31:17 +01:00

50 lines
1.4 KiB
JavaScript

var CACHE_NAME = "inventur_cache-v1";
var urlsToCache = [
'.',
'js/app.js',
'js/vue.js',
'js/accounting.min.js',
'js/moment-with-locales.min.js',
'js/model/article.js',
'js/model/inventory_article.js'
];
self.addEventListener('install', function(event){
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache){
console.log("Cache opened");
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', function(event){
event.respondWith(
caches.match(event.request)
.then(function(response){
if (response) {
return response;
}
var fetchRequest = event.request.clone();
return fetch(fetchRequest).then(
function(response){
if(!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
var responseToCache = response.clone();
caches.open(CACHE_NAME)
.then(function(cache){
cache.put(event.request, responseToCache);
});
return response;
}
)
})
);
});