Update service-worker.js

This commit is contained in:
FURK4NGG
2025-03-04 00:45:42 +03:00
committed by GitHub
parent b05bc625ff
commit 0c94c77ce7
+29 -43
View File
@@ -1,20 +1,20 @@
const CURRENT_VERSION = 'v67'; // Versiyon numarasını güncelle const CURRENT_VERSION = 'v68';
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',
@@ -44,48 +44,34 @@ self.addEventListener('install', event => {
caches.open(CACHE_NAME).then(cache => { caches.open(CACHE_NAME).then(cache => {
console.log(`Caching files for version: ${CURRENT_VERSION}`); console.log(`Caching files for version: ${CURRENT_VERSION}`);
return cache.addAll(urlsToCache); return cache.addAll(urlsToCache);
}).catch(error => {
console.error('Error caching files: ', error);
})
);
});
// Activate event - Delete old caches and load new ones
self.addEventListener('activate', event => {
console.log('Activate event fired');
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheName !== CACHE_NAME) {
console.log(`Deleting old cache: ${cacheName}`);
return caches.delete(cacheName);
}
})
);
}).then(() => {
console.log('All old caches deleted.');
return caches.open(CACHE_NAME).then(cache => {
console.log(`Caching new files for version: ${CURRENT_VERSION}`);
return cache.addAll(urlsToCache);
});
}).then(() => {
console.log(`Cache updated to version: ${CURRENT_VERSION}`);
return self.clients.claim();
}).catch(error => {
console.error('Error during cache activation: ', error);
}) })
); );
}); });
// Fetch event - Serve from cache if available, else fetch from network // Fetch event - Serve from cache if available, else fetch from network
self.addEventListener('fetch', event => { self.addEventListener('fetch', event => {
console.log('Fetch event fired for: ', event.request.url);
event.respondWith( event.respondWith(
caches.match(event.request).then(response => { caches.match(event.request).then(response => {
return response || fetch(event.request); return response || fetch(event.request);
}).catch(error => { })
console.error('Error fetching request: ', error); );
});
// Activate event - Delete old caches if version is different
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheName.startsWith('cache-') && cacheName !== CACHE_NAME) {
console.log(`Deleting old cache: ${cacheName}`);
return caches.delete(cacheName);
}
})
);
}).then(() => {
console.log(`Cache updated to version: ${CURRENT_VERSION}`);
return self.clients.claim();
}) })
); );
}); });