37 lines
938 B
JavaScript
37 lines
938 B
JavaScript
const CACHE_NAME = 'instinct-app-cache';
|
|
const urlsToCache = [
|
|
'/instinct/',
|
|
'/instinct/index.html',
|
|
'/instinct/manifest.json',
|
|
];
|
|
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
return cache.addAll(urlsToCache);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
event.respondWith(
|
|
caches.match(event.request).then((response) => {
|
|
return response || fetch(event.request);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
const cacheWhitelist = [CACHE_NAME];
|
|
event.waitUntil(
|
|
caches.keys().then((keyList) => {
|
|
return Promise.all(
|
|
keyList.map((key) => {
|
|
if (!cacheWhitelist.includes(key)) {
|
|
return caches.delete(key);
|
|
}
|
|
})
|
|
);
|
|
})
|
|
);
|
|
});
|