-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
94 lines (91 loc) · 3.75 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const staticCacheName = "site-static-v1";
const dynamicCache = "dynamic-static-v1";
const assets = [
"/",
"/index.html",
"/script.js",
"/app.js",
"/style.css",
"/images/Afternoon.png",
"/images/app-background.png",
"/images/Asset 1.png",
"/images/Morning.png",
"/images/Night.png",
"/images/Sunset.png",
"/icons/cloud.svg",
"/icons/history.svg",
"/icons/humidity.svg",
"/icons/magnifying-glass.svg",
"/icons/pressure.svg",
"/icons/refresh (1).svg",
"/icons/refresh.svg",
"/icons/save-button.svg",
"/icons/weather refresh.svg",
"/icons/wind.svg",
"/icons/windsock.svg",
// "https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@200;300;400;600;700&display",
// "https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@200;300;400;600;700&display=swap",
"https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@200;300;400;600;700&display=swap",
// "https://fonts.gstatic.com/s/nunitosans/v6/pe0qMImSLYBIv1o4X1M8cce9I9s.woff2",
// "https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9yAs5tU1E.woff2",
// "https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9iB85tU1E.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9yAs5iU1EQVg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9yAs5jU1EQVg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9yAs5tU1E.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc8WAc5iU1EQVg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc8WAc5jU1EQVg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc8WAc5tU1E.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe0qMImSLYBIv1o4X1M8cceyI9tScg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe0qMImSLYBIv1o4X1M8ccezI9tScg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe0qMImSLYBIv1o4X1M8cce9I9s.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9iB85iU1EQVg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9iB85jU1EQVg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9iB85tU1E.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc8GBs5iU1EQVg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc8GBs5jU1EQVg.woff2",
"https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc8GBs5tU1E.woff2",
// "https://fonts.gstatic.com/s/nunitosans/v6/pe0qMImSLYBIv1o4X1M8cce9I9s.woff2",
// "https://fonts.gstatic.com/s/nunitosans/v6/pe03MImSLYBIv1o4X1M8cc9yAs5tU1E.woff2",
"https://cdn.loom.com/assets/fonts/inter/Inter-UI-Regular.woff2",
];
//install service workers
self.addEventListener("install", (evt) => {
console.log("Service Worker has been installed");
evt.waitUntil(
caches.open(staticCacheName).then((cache) => {
console.log("caching shell assets");
cache.addAll(assets);
})
);
});
//activate service worker
self.addEventListener("activate", (evt) => {
// console.log("Service worker has been activated");
evt.waitUntil(
caches.keys().then((keys) => {
// console.log(keys);
return Promise.all(
keys
.filter((key) => key !== staticCacheName && key === dynamicCache)
.map((key) => caches.delete(key))
);
})
);
});
//register service worker with fetch api
self.addEventListener("fetch", (evt) => {
// console.log("fetch", evt);
evt.respondWith(
caches.match(evt.request).then((cacheRes) => {
return (
cacheRes ||
fetch(evt.request).then((fetchRes) => {
return caches.open(dynamicCache).then((cache) => {
cache.put(evt.request.url, fetchRes.clone());
return fetchRes;
});
})
);
})
);
});