-
Notifications
You must be signed in to change notification settings - Fork 6
/
sw.js
77 lines (72 loc) · 1.94 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
const cacheName = "v3";
const cacheAssets = [
"index.html",
"./models/arrow2.png",
"./models/ccd.gltf",
"./models/civil.gltf",
"./models/dg.gltf",
"./models/gtac.gltf",
"./models/iit.gltf",
"./models/lc.gltf",
"./models/karma.gltf",
"./models/lib.gltf",
"./models/lt1.gltf",
"./models/scene.gltf",
"./models/scene.bin",
"./models/sb.gltf",
"./models/sryia.gltf",
"./models/Welcome.gltf",
"./models/Welcome.bin",
"./models/direction2atccd.bin",
"./models/direction2atcivil.bin",
"./models/direction2atdg.bin",
"./models/direction2atgamcha.bin",
"./models/direction2atkarma.bin",
"./models/directionatiitlogo.bin",
"./models/direction2atlc.bin",
"./models/direction2atlib.bin",
"./models/direction2atsb.bin",
"./models/direction2atviswarayya.bin",
"./models/directionatLT1.bin",
"./models/directionatvt.bin",
"./SVG/csi.svg",
"./SVG/augnex.svg",
"./SVG/Technex.svg",
"./ar.js",
"./canvas.js"
];
// Call Install Event
self.addEventListener("install", e => {
console.log("Service Worker: Installed");
e.waitUntil(
caches
.open(cacheName)
.then(cache => {
console.log("Service Worker: Caching Files");
cache.addAll(cacheAssets);
})
.then(() => self.skipWaiting())
);
});
// Call Activate Event
self.addEventListener("activate", e => {
console.log("Service Worker: Activated");
// Remove unwanted caches
e.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== cacheName) {
console.log("Service Worker: Clearing Old Cache");
return caches.delete(cache);
}
})
);
})
);
});
// Call Fetch Event
self.addEventListener("fetch", e => {
console.log("Service Worker: Fetching");
e.respondWith(fetch(e.request).catch(() => caches.match(e.request)));
});