You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
69 lines
2.2 KiB
var staticCacheName = "django-pwa-v" + new Date().getTime();
|
|
|
|
self.addEventListener("install", event => {
|
|
this.skipWaiting();
|
|
|
|
const urlsToCache = [
|
|
'/static/app/css/bootstrap.css',
|
|
'/static/app/css/custom.css',
|
|
'/static/app/js/dbcontrol.js',
|
|
'/static/app/js/timer.js',
|
|
'/static/app/js/welcomeControl.js',
|
|
'/static/app/js/exportDB.js',
|
|
'/static/app/js/importDB.js',
|
|
'/static/app/js/UpdateInfoControl.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'
|
|
];
|
|
|
|
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(
|
|
cacheNames
|
|
.filter(cacheName => (cacheName.startsWith("django-pwa-")))
|
|
.filter(cacheName => (cacheName !== staticCacheName))
|
|
.map(cacheName => caches.delete(cacheName))
|
|
);
|
|
})
|
|
);
|
|
});
|
|
|
|
// // 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');
|
|
// })
|
|
// )
|
|
// });
|