Update static/service-worker.js
Browse files- static/service-worker.js +4 -45
static/service-worker.js
CHANGED
|
@@ -1,32 +1,21 @@
|
|
| 1 |
const CACHE_NAME = 'digital-gut-v1';
|
| 2 |
const ASSETS_TO_CACHE = [
|
| 3 |
'/',
|
| 4 |
-
'/
|
|
|
|
| 5 |
'/assets/main_music.mp3',
|
| 6 |
-
// 아이콘 파일들
|
| 7 |
-
'/static/icons/icon-72x72.png',
|
| 8 |
-
'/static/icons/icon-96x96.png',
|
| 9 |
-
'/static/icons/icon-128x128.png',
|
| 10 |
-
'/static/icons/icon-144x144.png',
|
| 11 |
-
'/static/icons/icon-152x152.png',
|
| 12 |
'/static/icons/icon-192x192.png',
|
| 13 |
-
'/static/icons/icon-384x384.png',
|
| 14 |
'/static/icons/icon-512x512.png'
|
| 15 |
];
|
| 16 |
|
| 17 |
-
// 설치 시 캐시
|
| 18 |
self.addEventListener('install', (event) => {
|
| 19 |
event.waitUntil(
|
| 20 |
caches.open(CACHE_NAME)
|
| 21 |
-
.then((cache) =>
|
| 22 |
-
console.log('Opened cache');
|
| 23 |
-
return cache.addAll(ASSETS_TO_CACHE);
|
| 24 |
-
})
|
| 25 |
.then(() => self.skipWaiting())
|
| 26 |
);
|
| 27 |
});
|
| 28 |
|
| 29 |
-
// 활성화 시 이전 캐시 정리
|
| 30 |
self.addEventListener('activate', (event) => {
|
| 31 |
event.waitUntil(
|
| 32 |
caches.keys().then((cacheNames) => {
|
|
@@ -41,44 +30,14 @@ self.addEventListener('activate', (event) => {
|
|
| 41 |
);
|
| 42 |
});
|
| 43 |
|
| 44 |
-
// 네트워크 요청 처리
|
| 45 |
self.addEventListener('fetch', (event) => {
|
| 46 |
event.respondWith(
|
| 47 |
caches.match(event.request)
|
| 48 |
.then((response) => {
|
| 49 |
-
// 캐시에 있으면 캐시된 버전 반환
|
| 50 |
if (response) {
|
| 51 |
return response;
|
| 52 |
}
|
| 53 |
-
|
| 54 |
-
// 캐시에 없으면 네트워크 요청
|
| 55 |
-
return fetch(event.request).then(
|
| 56 |
-
(response) => {
|
| 57 |
-
// 유효하지 않은 응답이면 그대로 반환
|
| 58 |
-
if (!response || response.status !== 200 || response.type !== 'basic') {
|
| 59 |
-
return response;
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
// 응답을 캐시에 저장
|
| 63 |
-
const responseToCache = response.clone();
|
| 64 |
-
caches.open(CACHE_NAME)
|
| 65 |
-
.then((cache) => {
|
| 66 |
-
cache.put(event.request, responseToCache);
|
| 67 |
-
});
|
| 68 |
-
|
| 69 |
-
return response;
|
| 70 |
-
}
|
| 71 |
-
);
|
| 72 |
})
|
| 73 |
);
|
| 74 |
-
});
|
| 75 |
-
|
| 76 |
-
// 백그라운드 동기화
|
| 77 |
-
self.addEventListener('sync', (event) => {
|
| 78 |
-
if (event.tag === 'syncData') {
|
| 79 |
-
event.waitUntil(
|
| 80 |
-
// 오프라인 데이터 동기화 로직
|
| 81 |
-
syncData()
|
| 82 |
-
);
|
| 83 |
-
}
|
| 84 |
});
|
|
|
|
| 1 |
const CACHE_NAME = 'digital-gut-v1';
|
| 2 |
const ASSETS_TO_CACHE = [
|
| 3 |
'/',
|
| 4 |
+
'/gradio',
|
| 5 |
+
'/manifest.json',
|
| 6 |
'/assets/main_music.mp3',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
'/static/icons/icon-192x192.png',
|
|
|
|
| 8 |
'/static/icons/icon-512x512.png'
|
| 9 |
];
|
| 10 |
|
|
|
|
| 11 |
self.addEventListener('install', (event) => {
|
| 12 |
event.waitUntil(
|
| 13 |
caches.open(CACHE_NAME)
|
| 14 |
+
.then((cache) => cache.addAll(ASSETS_TO_CACHE))
|
|
|
|
|
|
|
|
|
|
| 15 |
.then(() => self.skipWaiting())
|
| 16 |
);
|
| 17 |
});
|
| 18 |
|
|
|
|
| 19 |
self.addEventListener('activate', (event) => {
|
| 20 |
event.waitUntil(
|
| 21 |
caches.keys().then((cacheNames) => {
|
|
|
|
| 30 |
);
|
| 31 |
});
|
| 32 |
|
|
|
|
| 33 |
self.addEventListener('fetch', (event) => {
|
| 34 |
event.respondWith(
|
| 35 |
caches.match(event.request)
|
| 36 |
.then((response) => {
|
|
|
|
| 37 |
if (response) {
|
| 38 |
return response;
|
| 39 |
}
|
| 40 |
+
return fetch(event.request);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
})
|
| 42 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
});
|