-
Notifications
You must be signed in to change notification settings - Fork 9
/
service-worker.js
47 lines (39 loc) · 1.43 KB
/
service-worker.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
const cacheName = "cache-v4";
self.addEventListener('install', e => {
e.waitUntil(
caches.open(cacheName).then(cache => {
cache.addAll([
"/",
"/manifest.json",
"/index.html",
"/static/media/favicon.png",
"/static/media/cyclone.png",
"/static/media/background.png",
"/static/js/sw.js",
"/static/js/rsmc.js",
"/static/js/new_point.js",
"/static/js/hurdat.js",
"/static/js/pages.js",
"/static/js/ibtracs.js",
"/static/js/manual_input.js",
"/static/js/generate.js",
"/static/js/atcf.js",
"/static/js/file_upload.js",
"/static/css/style.css"
])
.then(() => {console.log("Cached files!")})
})
);
});
self.addEventListener('fetch', e => {
e.respondWith((async () => {
const r = await caches.match(e.request);
console.log('Fetching', e.request.url);
if (r && (e.request.url === "https://cdn.trackgen.codingcactus.codes/map.jpg" || !navigator.onLine)) return r;
const response = await fetch(e.request);
const cache = await caches.open(cacheName);
console.log('Caching', e.request.url);
await cache.put(e.request.url, response.clone());
return response;
})());
});