Update service-worker.js
This commit is contained in:
+10
-82
@@ -1,89 +1,17 @@
|
|||||||
const CURRENT_VERSION = 'v51'; // Güncel versiyonu buraya yaz
|
|
||||||
const CACHE_NAME = `cache-${CURRENT_VERSION}`;
|
|
||||||
|
|
||||||
const urlsToCache = [
|
|
||||||
'/',
|
|
||||||
'/index.html',
|
|
||||||
'/home_en.html',
|
|
||||||
'/home_tr.html',
|
|
||||||
'/404.html',
|
|
||||||
'/CSS/unpkg.comswiper@8swiper-bundle.min.css',
|
|
||||||
'/FONTS/Inconsolata.woff2',
|
|
||||||
'/FONTS/Jaro.woff2',
|
|
||||||
'/FONTS/Monomakh.woff2',
|
|
||||||
'/FONTS/Montserrat.woff2',
|
|
||||||
'/FONTS/TacOne.woff2',
|
|
||||||
'/FONTS/Teko.woff2',
|
|
||||||
'/JAVASCRIPT/1.js',
|
|
||||||
'/JAVASCRIPT/tr/1.js',
|
|
||||||
'/JAVASCRIPT/darkmode-js.min.js',
|
|
||||||
'/JAVASCRIPT/gsap.min.js',
|
|
||||||
'/JAVASCRIPT/swiper-bundle.min.js',
|
|
||||||
'/service-worker.js',
|
|
||||||
'/img/profile_photo1.webp',
|
|
||||||
'/img/character1.webp',
|
|
||||||
'/img/character2.webp',
|
|
||||||
'/img/character3.webp',
|
|
||||||
'/img/ai.webp',
|
|
||||||
'/img/app.webp',
|
|
||||||
'/img/cyber.webp',
|
|
||||||
'/img/game.webp',
|
|
||||||
'/img/robotic.webp',
|
|
||||||
'/img/web.webp',
|
|
||||||
'/img/up.webp',
|
|
||||||
'/img/icon.ico',
|
|
||||||
'/sitemap.xml',
|
|
||||||
'/manifest.json',
|
|
||||||
'/robots.txt',
|
|
||||||
'/.htaccess.txt'
|
|
||||||
];
|
|
||||||
|
|
||||||
// Install event - Yeni versiyonu yükle
|
|
||||||
self.addEventListener('install', event => {
|
|
||||||
event.waitUntil(
|
|
||||||
(async () => {
|
|
||||||
const cache = await caches.open(CACHE_NAME);
|
|
||||||
console.log(`Caching files for version: ${CURRENT_VERSION}`);
|
|
||||||
await cache.addAll(urlsToCache);
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
self.skipWaiting(); // Yeni versiyonu anında aktif et
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fetch event - Cache varsa kullan, yoksa ağdan al
|
|
||||||
self.addEventListener('fetch', event => {
|
|
||||||
event.respondWith(
|
|
||||||
caches.match(event.request).then(response => {
|
|
||||||
return response || fetch(event.request);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Activate event - Eski cache'leri KESİN olarak sil
|
|
||||||
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(
|
||||||
|
cacheNames.map(cacheName => {
|
||||||
// Eski cache’leri sil
|
if (cacheName.startsWith('cache-')) {
|
||||||
await Promise.all(
|
const cacheVersion = parseInt(cacheName.replace('cache-v', ''), 10);
|
||||||
cacheNames.map(async cacheName => {
|
if (cacheVersion < 50) { // v50 öncesini sil
|
||||||
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}`);
|
|
||||||
|
|
||||||
await self.clients.claim();
|
|
||||||
|
|
||||||
// Açık sekmeleri yenile
|
|
||||||
const clients = await self.clients.matchAll({ type: 'window', includeUncontrolled: true });
|
|
||||||
clients.forEach(client => {
|
|
||||||
client.navigate(client.url);
|
|
||||||
});
|
|
||||||
})()
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user