37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
// Service Worker
|
|
// hier wird alles lokal gespeichert
|
|
// der "install" event wird beim ServiceWorker Startup aufgerufen
|
|
|
|
self.addEventListener('install', function(e) {
|
|
console.log('install');
|
|
|
|
// waitUntil tells the browser that the install event is not finished until we have
|
|
// cached all of our files
|
|
e.waitUntil(
|
|
// Here we call our cache "myonsenuipwa", but you can name it anything unique
|
|
caches.open('myonsenuipwa').then(cache => {
|
|
// If the request for any of these resources fails, _none_ of the resources will be
|
|
// added to the cache.
|
|
return cache.addAll([
|
|
'/',
|
|
'/index.html',
|
|
'/manifest.json',
|
|
'https://unpkg.com/onsenui/css/onsenui.min.css',
|
|
'https://unpkg.com/onsenui/css/onsen-css-components.min.css',
|
|
'https://unpkg.com/onsenui/js/onsenui.min.js'
|
|
]);
|
|
})
|
|
);
|
|
|
|
});
|
|
|
|
|
|
// der fetch event wird abgefangen und stattdessen die lokale Datei geliefert
|
|
|
|
self.addEventListener('fetch', function(e) {
|
|
console.log('fetch');
|
|
e.respondWith(
|
|
caches.match(e.request)
|
|
.then(response => response || fetch(e.request))
|
|
);
|
|
}); |