Spaces:
Running
on
Zero
Running
on
Zero
Update service-worker.js
Browse files- service-worker.js +10 -27
service-worker.js
CHANGED
|
@@ -1,36 +1,19 @@
|
|
| 1 |
const CACHE_NAME = 'pawmatch-v1';
|
|
|
|
|
|
|
| 2 |
const urlsToCache = [
|
| 3 |
-
|
| 4 |
-
'
|
| 5 |
-
'
|
| 6 |
-
'
|
| 7 |
];
|
| 8 |
|
| 9 |
-
self.addEventListener('install',
|
| 10 |
event.waitUntil(
|
| 11 |
caches.open(CACHE_NAME)
|
| 12 |
-
.then(
|
| 13 |
-
console.log('
|
| 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 |
-
});
|
|
|
|
| 1 |
const CACHE_NAME = 'pawmatch-v1';
|
| 2 |
+
const BASE_PATH = self.location.pathname.replace('service-worker.js', '');
|
| 3 |
+
|
| 4 |
const urlsToCache = [
|
| 5 |
+
BASE_PATH,
|
| 6 |
+
BASE_PATH + 'manifest.json',
|
| 7 |
+
BASE_PATH + 'assets/icon-192.png',
|
| 8 |
+
BASE_PATH + 'assets/icon-512.png'
|
| 9 |
];
|
| 10 |
|
| 11 |
+
self.addEventListener('install', event => {
|
| 12 |
event.waitUntil(
|
| 13 |
caches.open(CACHE_NAME)
|
| 14 |
+
.then(cache => {
|
| 15 |
+
console.log('快取開啟成功');
|
| 16 |
return cache.addAll(urlsToCache);
|
| 17 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
);
|
| 19 |
+
});
|