-
Notifications
You must be signed in to change notification settings - Fork 1
/
serviceWorker.js
67 lines (64 loc) · 1.95 KB
/
serviceWorker.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
var GHPATH = "/mapify-map-app"
var APP_PREFIX = "mapify_"
var VERSION = "version_006"
var CACHE_NAME = APP_PREFIX + VERSION
const assets = [
`${GHPATH}/`,
`${GHPATH}/index.html`,
`${GHPATH}/disclaimer.html`,
`${GHPATH}/css/map.css`,
`${GHPATH}/css/material-icons.css`,
`${GHPATH}/css/disclaimer.css`,
`${GHPATH}/scripts/map.js`,
`${GHPATH}/scripts/algorithm.js`,
`${GHPATH}/fonts/GoogleSans-Medium.ttf`,
`${GHPATH}/ico/tab-ico.png`,
`${GHPATH}/libs/materialize/css/materialize.min.css`,
`${GHPATH}/libs/materialize/js/materialize.min.js`,
`${GHPATH}/utils/lottie-player.js`,
`${GHPATH}/utils/material-theme-control.js`,
`${GHPATH}/utils/animations/86746-loading-blash.json`,
`${GHPATH}/maps/Abstract_Maps/absMap3.png`,
`${GHPATH}/maps/Real_Maps/gMaps5.png`,
`${GHPATH}/maps/Real_Maps/gMaps6.png`,
`${GHPATH}/maps/Real_Maps/gMaps7.png`,
`${GHPATH}/maps/Real_Maps/gMaps8.png`,
`${GHPATH}/maps/Real_Maps/gMaps9.png`,
`${GHPATH}/maps/Industries/indMap1.jpg`,
`${GHPATH}/maps/Industries/indMap2.jpg`,
`${GHPATH}/maps/Industries/indMap3.png`,
`${GHPATH}/sounds/party-trumpet.wav`,
`${GHPATH}/sounds/mixkit-cool-interface-click-tone-2568.wav`,
`${GHPATH}/sounds/mixkit-click-error-1110.wav`,
]
self.addEventListener("install", (e) => {
e.waitUntil(async () => {
const cache = await caches.open(CACHE_NAME)
await cache.addAll(assets)
})
})
self.addEventListener("fetch", (fetchEvent) => {
fetchEvent.respondWith(
caches.match(fetchEvent.request).then((res) => {
return res || fetch(fetchEvent.request)
})
)
})
self.addEventListener("activate", (e) => {
e.waitUntil(
caches.keys().then(function (keyList) {
var cacheWhitelist = keyList.filter((key) => {
return key.indexOf(APP_PREFIX)
})
cacheWhitelist.push(CACHE_NAME)
return Promise.all(
keyList.map((key, i) => {
if (cacheWhitelist.indexOf(key) === -1) {
console.log("Deleting cache : " + keyList[i])
return caches.delete(keyList[i])
}
})
)
})
)
})