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.
piomint/app/static/app/js/serviceworker.js

42 lines
1.2 KiB

var staticCacheName = "django-pwa-v" + new Date().getTime();
var filesToCache = [
'/app/home',
];
// 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)));
// })
// )
// });
// Clear cache on activate
self.addEventListener('activate', event => {
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');
})
)
});

Powered by TurnKey Linux.