Update service-worker.js
This commit is contained in:
+11
-10
@@ -1,8 +1,8 @@
|
|||||||
const CURRENT_VERSION = 'v50'; // Versiyonu güncelle
|
const CURRENT_VERSION = 'v51'; // Güncel versiyonu buraya yaz
|
||||||
const CACHE_NAME = `cache-${CURRENT_VERSION}`;
|
const CACHE_NAME = `cache-${CURRENT_VERSION}`;
|
||||||
|
|
||||||
const urlsToCache = [
|
const urlsToCache = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
'/home_en.html',
|
'/home_en.html',
|
||||||
'/home_tr.html',
|
'/home_tr.html',
|
||||||
@@ -47,7 +47,7 @@ self.addEventListener('install', event => {
|
|||||||
await cache.addAll(urlsToCache);
|
await cache.addAll(urlsToCache);
|
||||||
})()
|
})()
|
||||||
);
|
);
|
||||||
self.skipWaiting(); // Yeni versiyonu anında etkinleştir
|
self.skipWaiting(); // Yeni versiyonu anında aktif et
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch event - Cache varsa kullan, yoksa ağdan al
|
// Fetch event - Cache varsa kullan, yoksa ağdan al
|
||||||
@@ -59,27 +59,28 @@ self.addEventListener('fetch', event => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Activate event - Eski cache'leri %100 temizle
|
// Activate event - Eski cache'leri KESİN olarak sil
|
||||||
self.addEventListener('activate', event => {
|
self.addEventListener('activate', event => {
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
(async () => {
|
(async () => {
|
||||||
const cacheNames = await caches.keys();
|
const cacheNames = await caches.keys();
|
||||||
|
|
||||||
// Tüm eski cache'leri temizle, sadece yeni olanı bırak
|
// Eski cache’leri sil
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
cacheNames.map(cacheName => {
|
cacheNames.map(async 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}`);
|
||||||
return caches.delete(cacheName);
|
await 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();
|
||||||
|
|
||||||
// Açık sekmeleri güncelle
|
// Açık sekmeleri yenile
|
||||||
const clients = await self.clients.matchAll({ type: 'window' });
|
const clients = await self.clients.matchAll({ type: 'window', includeUncontrolled: true });
|
||||||
clients.forEach(client => {
|
clients.forEach(client => {
|
||||||
client.navigate(client.url);
|
client.navigate(client.url);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user