Update service-worker.js

This commit is contained in:
FURK4NGG
2025-03-03 23:36:42 +03:00
committed by GitHub
parent fbdf785db4
commit d8f0d924a4
+9 -6
View File
@@ -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 => {
if (cacheName !== CACHE_NAME) {
console.log(`Deleting old cache: ${cacheName}`); console.log(`Deleting old cache: ${cacheName}`);
await caches.delete(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();