x
This commit is contained in:
parent
816c903681
commit
1e75f2df88
1 changed files with 26 additions and 6 deletions
|
|
@ -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) => {
|
||||
event.waitUntil(
|
||||
caches.open('instinct-app-cache').then((cache) => {
|
||||
return cache.addAll([
|
||||
'/',
|
||||
'index.html',
|
||||
'manifest.json',
|
||||
]);
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
return cache.addAll(urlsToCache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
|
@ -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);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue