Spaces:
Running
on
Zero
Running
on
Zero
Delete service-worker.js
Browse files- service-worker.js +0 -37
service-worker.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
const CACHE_NAME = 'pawmatch-v2';
|
| 2 |
-
const BASE_URL = self.location.pathname.replace('service-worker.js', '');
|
| 3 |
-
|
| 4 |
-
const urlsToCache = [
|
| 5 |
-
BASE_URL,
|
| 6 |
-
`${BASE_URL}manifest.json`,
|
| 7 |
-
`${BASE_URL}icon-192.png`,
|
| 8 |
-
`${BASE_URL}icon-512.png`
|
| 9 |
-
];
|
| 10 |
-
|
| 11 |
-
self.addEventListener('install', (event) => {
|
| 12 |
-
event.waitUntil(
|
| 13 |
-
caches.open(CACHE_NAME)
|
| 14 |
-
.then((cache) => {
|
| 15 |
-
console.log('Cache opened');
|
| 16 |
-
return cache.addAll(urlsToCache);
|
| 17 |
-
})
|
| 18 |
-
.then(() => self.skipWaiting())
|
| 19 |
-
.catch(error => console.error('Cache error:', error))
|
| 20 |
-
);
|
| 21 |
-
});
|
| 22 |
-
|
| 23 |
-
self.addEventListener('fetch', (event) => {
|
| 24 |
-
event.respondWith(
|
| 25 |
-
caches.match(event.request)
|
| 26 |
-
.then((response) => {
|
| 27 |
-
if (response) {
|
| 28 |
-
return response;
|
| 29 |
-
}
|
| 30 |
-
return fetch(event.request);
|
| 31 |
-
})
|
| 32 |
-
.catch(() => {
|
| 33 |
-
// 如果離線且快取中沒有,返回離線頁面或預設內容
|
| 34 |
-
return new Response('Offline');
|
| 35 |
-
})
|
| 36 |
-
);
|
| 37 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|