Update service-worker.js
This commit is contained in:
+11
-8
@@ -1,4 +1,4 @@
|
|||||||
const CURRENT_VERSION = 'v44';
|
const CURRENT_VERSION = 'v46';
|
||||||
const CACHE_NAME = `cache-${CURRENT_VERSION}`;
|
const CACHE_NAME = `cache-${CURRENT_VERSION}`;
|
||||||
|
|
||||||
const urlsToCache = [
|
const urlsToCache = [
|
||||||
@@ -58,16 +58,19 @@ self.addEventListener('fetch', event => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Activate event - delete old caches and update clients
|
// Activate event - delete all old caches and update clients
|
||||||
self.addEventListener('activate', event => {
|
self.addEventListener('activate', event => {
|
||||||
event.waitUntil((async () => {
|
event.waitUntil((async () => {
|
||||||
const cacheNames = await caches.keys();
|
const cacheNames = await caches.keys();
|
||||||
for (const cacheName of cacheNames) {
|
await Promise.all(
|
||||||
if (cacheName.startsWith('cache-') && cacheName !== CACHE_NAME) {
|
cacheNames.map(cacheName => {
|
||||||
console.log(`Deleting old cache: ${cacheName}`);
|
if (cacheName !== CACHE_NAME) {
|
||||||
await caches.delete(cacheName);
|
console.log(`Deleting old cache: ${cacheName}`);
|
||||||
}
|
return caches.delete(cacheName);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
console.log(`Cache updated to version: ${CURRENT_VERSION}`);
|
console.log(`Cache updated to version: ${CURRENT_VERSION}`);
|
||||||
await self.clients.claim();
|
await self.clients.claim();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user