Update service-worker.js
This commit is contained in:
+13
-36
@@ -1,4 +1,4 @@
|
|||||||
const CURRENT_VERSION = 'v58';
|
const CURRENT_VERSION = 'v59'; // Mevcut versiyon
|
||||||
const CACHE_NAME = `cache-${CURRENT_VERSION}`;
|
const CACHE_NAME = `cache-${CURRENT_VERSION}`;
|
||||||
|
|
||||||
const urlsToCache = [
|
const urlsToCache = [
|
||||||
@@ -38,48 +38,25 @@ const urlsToCache = [
|
|||||||
'/.htaccess.txt'
|
'/.htaccess.txt'
|
||||||
];
|
];
|
||||||
|
|
||||||
// Install event - cache files
|
// Activate event - Delete all old caches and then cache the new 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 and then cache the new version
|
|
||||||
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-') && cacheName !== CACHE_NAME) {
|
// Eski cache'leri siliyoruz
|
||||||
console.log(`Deleting old cache: ${cacheName}`);
|
console.log(`Deleting cache: ${cacheName}`);
|
||||||
return caches.delete(cacheName); // Eski cache'leri sil
|
return caches.delete(cacheName);
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
})
|
}).then(() => {
|
||||||
.then(() => {
|
console.log('All caches deleted');
|
||||||
// Eski cache'ler silindikten sonra, yeni cache'leri yükleyelim
|
// Yeni cache dosyalarını ekliyoruz
|
||||||
return caches.open(CACHE_NAME)
|
return caches.open(CACHE_NAME).then(cache => {
|
||||||
.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);
|
});
|
||||||
});
|
}).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();
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user