-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
56 lines (48 loc) · 1.57 KB
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const CACHE_STATIC_NAME = "static-v2";
const CACHE_DYNAMIC_NAME = "dynamic-v2";
const ROOT_URL = "/public/";
const STATIC_FILES = [
`${ROOT_URL}`,
`${ROOT_URL}index.html`,
`${ROOT_URL}src/js/external/perlin.js`,
`${ROOT_URL}src/js/app.js`,
`${ROOT_URL}src/js/cursor.js`,
`${ROOT_URL}src/js/debounce.js`,
`${ROOT_URL}src/css/style.css`,
`${ROOT_URL}src/assets/videos/about.mp4`,
`${ROOT_URL}src/assets/images/cover.png`,
`${ROOT_URL}src/assets/images/astro.jpeg`,
`${ROOT_URL}src/assets/images/hellowean.jpeg`,
`${ROOT_URL}src/assets/images/horror.jpeg`,
`${ROOT_URL}src/assets/images/movie.jpeg`,
`https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600;700;800;900&display=swap`,
];
self.addEventListener("install", function (event) {
event.waitUntil(
(async () => {
const cache = await caches.open(CACHE_STATIC_NAME)
return cache.addAll(STATIC_FILES);
})()
);
});
self.addEventListener("activate", (event) => {
return self.clients.claim();
});
self.addEventListener("fetch", (event) => {
event.respondWith(
(async () => {
const cachedResponse = await caches.match(event.request);
if (cachedResponse) {
return cachedResponse;
}
const response = await fetch(event.request);
if (!response || response.status !== 200 || response.type !== "basic") {
return response;
}
const responseToCache = response.clone();
const cache = await caches.open(CACHE_DYNAMIC_NAME);
await cache.put(event.request, responseToCache);
return response;
})()
);
});