This commit is contained in:
Omar Najjar 2024-07-06 23:41:21 +10:00
parent 816c903681
commit 1e75f2df88

View file

@ -1,11 +1,16 @@
const CACHE_NAME = 'instinct-app-cache';
const urlsToCache = [
'./',
'./index.html',
'./manifest.json',
'./icon-192x192.png',
'./icon-512x512.png',
];
self.addEventListener('install', (event) => { self.addEventListener('install', (event) => {
event.waitUntil( event.waitUntil(
caches.open('instinct-app-cache').then((cache) => { caches.open(CACHE_NAME).then((cache) => {
return cache.addAll([ return cache.addAll(urlsToCache);
'/',
'index.html',
'manifest.json',
]);
}) })
); );
}); });
@ -17,3 +22,18 @@ self.addEventListener('fetch', (event) => {
}) })
); );
}); });
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);
}
})
);
})
);
});