35 lines
871 B
JavaScript
35 lines
871 B
JavaScript
const CACHE_NAME = 'kv-tube-v1';
|
|
const STATIC_CACHE_URLS = [
|
|
'/',
|
|
'/static/css/style.css',
|
|
'/static/js/main.js',
|
|
'/static/icons/icon-192x192.png',
|
|
'/static/icons/icon-512x512.png',
|
|
'/static/favicon.ico'
|
|
];
|
|
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME)
|
|
.then(cache => cache.addAll(STATIC_CACHE_URLS))
|
|
);
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
event.respondWith(
|
|
caches.match(event.request)
|
|
.then(response => response || fetch(event.request))
|
|
);
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then(cacheNames => {
|
|
return Promise.all(
|
|
cacheNames.filter(cacheName => {
|
|
return cacheName.startsWith('kv-tube-') && cacheName !== CACHE_NAME;
|
|
}).map(cacheName => caches.delete(cacheName))
|
|
);
|
|
})
|
|
);
|
|
});
|