-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
59 lines (56 loc) · 2.06 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
const cacheName = 'Tapmapcache';
// Cache all the files to make a PWA
self.addEventListener('install', e => {
e.waitUntil(
caches.open(cacheName).then(cache => {
// Our application only has two files here index.html and manifest.json
// but you can add more such as style.css as your app grows
return cache.addAll([
'./',
'./index.html',
'./manifest.json',
'./images/africa.png',
'./images/africa.png',
'./images/asia.png',
'./images/europe.png',
'./images/logo.png',
'./images/northamerica.png',
'./images/oceania.png',
'./images/pwa-192x192.png',
'./images/pwa-384x384.png',
'./images/pwa-512x512.png',
'./images/southamerica.png',
'./js/continent.js',
'./js/d3.v5.min.js',
'./js/sweetalert1.js',
'./js/sweetalert2.js',
'./js/topojson.v2.min.js',
'./json/africa.json',
'./json/asia.json',
'./json/europe.json',
'./json/northamerica.json',
'./json/oceania.json',
'./json/southamerica.json',
'./json/world.json',
'./africa.html',
'./asia.html',
'./europe.html',
'./northamerica.html',
'./southamerica.html',
'./world.html'
]);
})
);
});
// Our service worker will intercept all fetch requests
// and check if we have cached the file
// if so it will serve the cached file
self.addEventListener('fetch', event => {
event.respondWith(
caches.open(cacheName)
.then(cache => cache.match(event.request, { ignoreSearch: true }))
.then(response => {
return response || fetch(event.request);
})
);
});