-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
32 lines (30 loc) · 1.01 KB
/
sw.js
File metadata and controls
32 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const CACHE_NAME = 'cube-timer-pwa-cache-v1';
const urlsToCache = [
'./', // Kök dizini (index.html'i temsil eder)
'./index.html', // Ana dosyayı açıkça belirtmek iyidir
'https://cdn.jsdelivr.net/npm/chart.js' // Dışarıdan çekilen kütüphane
];
// Yükleme olayı: Gerekli dosyaları önbelleğe alır
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
// Fetch olayı: Önbellekteki dosyaları sunar veya ağdan getirir
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Önbellekte varsa, önbellekten sun
if (response) {
return response;
}
// Yoksa, ağdan getirmeyi dene
return fetch(event.request);
})
);
});