Create service-worker.js
Browse files- service-worker.js +36 -0
service-worker.js
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const CACHE_NAME = 'digital-gut-v1';
|
2 |
+
const urlsToCache = [
|
3 |
+
'/',
|
4 |
+
'/assets/main_music.mp3',
|
5 |
+
'/assets/icons/*',
|
6 |
+
// 캐시할 다른 리소스들 추가
|
7 |
+
];
|
8 |
+
|
9 |
+
self.addEventListener('install', (event) => {
|
10 |
+
event.waitUntil(
|
11 |
+
caches.open(CACHE_NAME)
|
12 |
+
.then((cache) => cache.addAll(urlsToCache))
|
13 |
+
);
|
14 |
+
});
|
15 |
+
|
16 |
+
self.addEventListener('fetch', (event) => {
|
17 |
+
event.respondWith(
|
18 |
+
caches.match(event.request)
|
19 |
+
.then((response) => response || fetch(event.request))
|
20 |
+
);
|
21 |
+
});
|
22 |
+
|
23 |
+
self.addEventListener('activate', (event) => {
|
24 |
+
const cacheWhitelist = [CACHE_NAME];
|
25 |
+
event.waitUntil(
|
26 |
+
caches.keys().then((cacheNames) => {
|
27 |
+
return Promise.all(
|
28 |
+
cacheNames.map((cacheName) => {
|
29 |
+
if (cacheWhitelist.indexOf(cacheName) === -1) {
|
30 |
+
return caches.delete(cacheName);
|
31 |
+
}
|
32 |
+
})
|
33 |
+
);
|
34 |
+
})
|
35 |
+
);
|
36 |
+
});
|