Update service-worker.js

This commit is contained in:
FURK4NGG
2025-03-04 00:04:09 +03:00
committed by GitHub
parent 37597edf86
commit 15a28e3ee2
+10 -7
View File
@@ -1,4 +1,4 @@
const CURRENT_VERSION = 'v54'; const CURRENT_VERSION = 'v56';
const CACHE_NAME = `cache-${CURRENT_VERSION}`; const CACHE_NAME = `cache-${CURRENT_VERSION}`;
const urlsToCache = [ const urlsToCache = [
@@ -58,23 +58,26 @@ self.addEventListener('fetch', event => {
); );
}); });
// Activate event - delete old caches if version is different // Activate event - delete all old caches and then cache the new version
self.addEventListener('activate', event => { self.addEventListener('activate', event => {
event.waitUntil( event.waitUntil(
caches.keys().then(cacheNames => { caches.keys().then(cacheNames => {
return Promise.all( return Promise.all(
cacheNames.map(cacheName => { cacheNames.map(cacheName => {
// Silinmesi gereken eski cache'leri kontrol et
if (cacheName.startsWith('cache-')) { if (cacheName.startsWith('cache-')) {
// Eski versiyonları CURRENT_VERSION ile karşılaştır // Eski tüm cache'leri sil
const cacheVersion = cacheName.replace('cache-', '');
if (cacheVersion !== CURRENT_VERSION) { // Eğer eski versiyon ise sil
console.log(`Deleting old cache: ${cacheName}`); console.log(`Deleting old cache: ${cacheName}`);
return caches.delete(cacheName); return caches.delete(cacheName);
} }
}
}) })
); );
}).then(() => {
// Yeni cache'i yükle
return caches.open(CACHE_NAME)
.then(cache => {
console.log(`Caching files for version: ${CURRENT_VERSION}`);
return cache.addAll(urlsToCache);
});
}).then(() => { }).then(() => {
console.log(`Cache updated to version: ${CURRENT_VERSION}`); console.log(`Cache updated to version: ${CURRENT_VERSION}`);
return self.clients.claim(); return self.clients.claim();