Update service-worker.js
This commit is contained in:
+2
-68
@@ -1,83 +1,17 @@
|
|||||||
const CURRENT_VERSION = 'v72';
|
|
||||||
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 - 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);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Activate event - delete old caches if version is different
|
|
||||||
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 => {
|
||||||
if (cacheName.startsWith('cache-')) {
|
if (cacheName.startsWith('cache-')) {
|
||||||
const cacheVersion = parseInt(cacheName.replace('cache-', ''), 10);
|
const cacheVersion = parseInt(cacheName.replace('cache-v', ''), 10);
|
||||||
|
if (cacheVersion < 80) { // v50 öncesini sil
|
||||||
// Eğer mevcut cache versiyonu, CURRENT_VERSION'dan küçükse, sil
|
|
||||||
if (cacheVersion < parseInt(CURRENT_VERSION.replace('v', ''), 10)) {
|
|
||||||
console.log(`Deleting old cache: ${cacheName}`);
|
console.log(`Deleting old cache: ${cacheName}`);
|
||||||
return caches.delete(cacheName);
|
return caches.delete(cacheName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}).then(() => {
|
|
||||||
console.log(`Cache updated to version: ${CURRENT_VERSION}`);
|
|
||||||
return self.clients.claim();
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user