Spaces:
Running
on
Zero
Running
on
Zero
Update service-worker.js
Browse files- service-worker.js +27 -19
service-worker.js
CHANGED
@@ -1,28 +1,36 @@
|
|
1 |
const CACHE_NAME = 'pawmatch-v1';
|
2 |
const urlsToCache = [
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
];
|
8 |
|
9 |
-
// 安裝事件處理器
|
10 |
self.addEventListener('install', function(event) {
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
});
|
19 |
|
20 |
-
// 請求處理器
|
21 |
self.addEventListener('fetch', function(event) {
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
});
|
|
|
1 |
const CACHE_NAME = 'pawmatch-v1';
|
2 |
const urlsToCache = [
|
3 |
+
'./',
|
4 |
+
'./manifest.json',
|
5 |
+
'./assets/icon-192.png',
|
6 |
+
'./assets/icon-512.png'
|
7 |
];
|
8 |
|
|
|
9 |
self.addEventListener('install', function(event) {
|
10 |
+
event.waitUntil(
|
11 |
+
caches.open(CACHE_NAME)
|
12 |
+
.then(function(cache) {
|
13 |
+
console.log('Cache opened successfully');
|
14 |
+
return cache.addAll(urlsToCache);
|
15 |
+
})
|
16 |
+
.catch(function(error) {
|
17 |
+
console.error('Cache initialization failed:', error);
|
18 |
+
})
|
19 |
+
);
|
20 |
});
|
21 |
|
|
|
22 |
self.addEventListener('fetch', function(event) {
|
23 |
+
event.respondWith(
|
24 |
+
caches.match(event.request)
|
25 |
+
.then(function(response) {
|
26 |
+
if (response) {
|
27 |
+
return response;
|
28 |
+
}
|
29 |
+
return fetch(event.request);
|
30 |
+
})
|
31 |
+
.catch(function(error) {
|
32 |
+
console.error('Fetch failed:', error);
|
33 |
+
return fetch(event.request);
|
34 |
+
})
|
35 |
+
);
|
36 |
});
|