|
|
|
|
@ -1,21 +1,47 @@
|
|
|
|
|
var staticCacheName = "django-pwa-VI" + new Date().getTime();
|
|
|
|
|
var filesToCache = [
|
|
|
|
|
'/app/home',
|
|
|
|
|
var staticCacheName = "django-pwa-v" + new Date().getTime();
|
|
|
|
|
|
|
|
|
|
self.addEventListener("install", event => {
|
|
|
|
|
this.skipWaiting();
|
|
|
|
|
|
|
|
|
|
const urlsToCache = [
|
|
|
|
|
'/app/home/',
|
|
|
|
|
'/static/app/css/bootstrap.css',
|
|
|
|
|
'/static/app/css/custom.css',
|
|
|
|
|
'/static/app/js/dbcontrol.js',
|
|
|
|
|
'/static/app/js/home.js',
|
|
|
|
|
'/static/app/js/timer.js',
|
|
|
|
|
'/static/app/js/welcomeControl.js',
|
|
|
|
|
'/static/app/images/refresh.png',
|
|
|
|
|
'/static/app/images/play.png',
|
|
|
|
|
'/static/app/images/pause.png',
|
|
|
|
|
'/static/app/images/stop.png',
|
|
|
|
|
'/static/app/images/addcircle.png'
|
|
|
|
|
];
|
|
|
|
|
// self.addEventListener("install", event => {
|
|
|
|
|
// this.skipWaiting();
|
|
|
|
|
// event.waitUntil(
|
|
|
|
|
// caches.open(staticCacheName)
|
|
|
|
|
// .then(cache => {
|
|
|
|
|
// return fetch('/app/home')
|
|
|
|
|
// .then(response => cache.put('/app/home', new Response(response.body)));
|
|
|
|
|
// })
|
|
|
|
|
// )
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
event.waitUntil(
|
|
|
|
|
caches.open(staticCacheName)
|
|
|
|
|
.then(cache => {
|
|
|
|
|
// Array von Promises, um alle Ressourcen zu cachen
|
|
|
|
|
return Promise.all(
|
|
|
|
|
urlsToCache.map(url => {
|
|
|
|
|
return fetch(url, { redirect: 'follow' }).then(response => {
|
|
|
|
|
// Prüfe, ob die Antwort erfolgreich und nicht umgeleitet wurde
|
|
|
|
|
if (response.ok && !response.redirected) {
|
|
|
|
|
return cache.put(url, response);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Clear cache on activate
|
|
|
|
|
self.addEventListener('activate', event => {
|
|
|
|
|
|
|
|
|
|
event.waitUntil(self.clients.claim());
|
|
|
|
|
|
|
|
|
|
event.waitUntil(
|
|
|
|
|
caches.keys().then(cacheNames => {
|
|
|
|
|
return Promise.all(
|
|
|
|
|
@ -28,15 +54,15 @@ self.addEventListener('activate', event => {
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// // Serve from Cache
|
|
|
|
|
// self.addEventListener("fetch", event => {
|
|
|
|
|
// event.respondWith(
|
|
|
|
|
// caches.match(event.request)
|
|
|
|
|
// .then(response => {
|
|
|
|
|
// return response || fetch(event.request);
|
|
|
|
|
// })
|
|
|
|
|
// .catch(() => {
|
|
|
|
|
// return caches.match('app/home');
|
|
|
|
|
// })
|
|
|
|
|
// )
|
|
|
|
|
// });
|
|
|
|
|
// Serve from Cache
|
|
|
|
|
self.addEventListener("fetch", event => {
|
|
|
|
|
event.respondWith(
|
|
|
|
|
caches.match(event.request)
|
|
|
|
|
.then(response => {
|
|
|
|
|
return response || fetch(event.request);
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
return caches.match('/app/home');
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
});
|