Update service-worker.js

This commit is contained in:
FURK4NGG
2025-03-03 21:47:43 +03:00
committed by GitHub
parent f678f5bddf
commit 2e401657dd
+16 -20
View File
@@ -1,4 +1,4 @@
const CURRENT_VERSION = 'v40'; const CURRENT_VERSION = 'v42';
const CACHE_NAME = `cache-${CURRENT_VERSION}`; const CACHE_NAME = `cache-${CURRENT_VERSION}`;
const urlsToCache = [ const urlsToCache = [
@@ -60,23 +60,19 @@ self.addEventListener('fetch', event => {
// Activate event - delete old caches and update clients // Activate event - delete old caches and update clients
self.addEventListener('activate', event => { self.addEventListener('activate', event => {
event.waitUntil( event.waitUntil((async () => {
caches.keys().then(cacheNames => { const cacheNames = await caches.keys();
return Promise.all( for (const cacheName of cacheNames) {
cacheNames.map(cacheName => { if (cacheName.startsWith('cache-') && cacheName !== CACHE_NAME) {
if (cacheName.startsWith('cache-') && 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}`);
); await self.clients.claim();
}).then(() => {
console.log(`Cache updated to version: ${CURRENT_VERSION}`); // Tüm açık sekmeleri yeni versiyona yönlendir
return self.clients.claim(); const clients = await self.clients.matchAll({ type: 'window' });
}).then(() => { clients.forEach(client => client.navigate(client.url));
self.clients.matchAll().then(clients => { })());
clients.forEach(client => client.navigate(client.url)); // Tüm sayfaları yenile
});
})
);
}); });