Update service-worker.js

This commit is contained in:
FURK4NGG
2025-03-04 00:28:32 +03:00
committed by GitHub
parent 76cf4b1f36
commit b0a8f50163
+32 -15
View File
@@ -1,20 +1,20 @@
const CURRENT_VERSION = 'v63'; // Mevcut versiyon const CURRENT_VERSION = 'v64'; // Versiyon numarasını güncelle
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',
'/404.html', '/404.html',
'/CSS/unpkg.comswiper@8swiper-bundle.min.css', '/CSS/unpkg.comswiper@8swiper-bundle.min.css',
'/FONTS/Inconsolata.woff2', '/FONTS/Inconsolata.woff2',
'/FONTS/Jaro.woff2', '/FONTS/Jaro.woff2',
'/FONTS/Monomakh.woff2', '/FONTS/Monomakh.woff2',
'/FONTS/Montserrat.woff2', '/FONTS/Montserrat.woff2',
'/FONTS/TacOne.woff2', '/FONTS/TacOne.woff2',
'/FONTS/Teko.woff2', '/FONTS/Teko.woff2',
'/JAVASCRIPT/1.js', '/JAVASCRIPT/1.js',
'/JAVASCRIPT/tr/1.js', '/JAVASCRIPT/tr/1.js',
'/JAVASCRIPT/darkmode-js.min.js', '/JAVASCRIPT/darkmode-js.min.js',
'/JAVASCRIPT/gsap.min.js', '/JAVASCRIPT/gsap.min.js',
@@ -38,27 +38,44 @@ const urlsToCache = [
'/.htaccess.txt' '/.htaccess.txt'
]; ];
// Activate event - Delete all old caches and then cache the new files // Install event - Cache files
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
console.log(`Caching files for version: ${CURRENT_VERSION}`);
return cache.addAll(urlsToCache);
})
);
});
// Activate event - Delete old caches and load new ones
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 => {
// Eski cache'leri siliyoruz
console.log(`Deleting cache: ${cacheName}`); console.log(`Deleting cache: ${cacheName}`);
return caches.delete(cacheName); return caches.delete(cacheName);
}) })
); );
}).then(() => { }).then(() => {
console.log('All caches deleted'); console.log('All caches deleted');
// Yeni cache dosyalarını ekliyoruz
return caches.open(CACHE_NAME).then(cache => { return caches.open(CACHE_NAME).then(cache => {
console.log(`Caching files for version: ${CURRENT_VERSION}`); console.log(`Caching new files for version: ${CURRENT_VERSION}`);
return cache.addAll(urlsToCache); 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(); // New cache activated
})
);
});
// Fetch event - Serve from cache if available, else fetch from network
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(response => {
return response || fetch(event.request);
}) })
); );
}); });