-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
101 lines (97 loc) · 2.67 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
95
96
97
98
99
100
101
const CACHE_NAME = "tni-cyber-site-5.5.5";
const OFFLINE_URL = "offline.html";
const assets = [
"/",
"/index.html",
"/aboutus.html",
"/activities.html",
"/cybersec.html",
"/termsofservice.html",
"/404.html",
"/offline.html",
"/badapple.html",
// common
"/common/navbar.html",
"/common/footer.html",
"/common/social-card.html",
"/common/cookie-banner.html",
"/common/messenger-plugin.html",
// css
"/css/style.css",
"/css/animate.min.css",
// js
"/js/app.js",
"/js/script.js",
"/js/carousel.js",
"/js/cookie.js",
"/js/hero.js",
"/js/version.js",
"/js/t.min.js",
"/js/wow.min.js",
// img
"/img/TNICyberWeb.png",
"/img/TNICyberICON.png",
"/img/TNICyberWebIcon.ico",
"/img/TNICyberWebIcon.png",
"/img/logoTNIWhite.png",
"/img/TNIIcon.png",
"/img/Open-source.png",
"/img/CTFTIME.png",
"/img/Coop Cop.png",
"/img/Coop Cop.png2",
"/img/CyberPic.jpg",
"/img/cybersec.jpg",
"/img/activity.jpg",
"/img/aboutme.png",
"/img/Head.png",
"/img/CyberPic_coop.png",
"/img/Takahashi.png",
"/img/finsec.jpg",
"/img/Cisco-Innovation-Challenge-2019.jpg",
"/img/RTAFCyberOps.png",
"/img/tni.jpg",
"/img/rick-roll.gif",
"/img/ring-resize-white-36.svg",
// media
"/audio/NeverGonnaGiveYouUp.mp3",
"/audio/silence.mp3",
"/video/badapple.mp4",
];
self.addEventListener("install", (installEvent) => {
installEvent.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
cache.addAll(assets);
cache.add(new Request(OFFLINE_URL, { cache: "reload" }));
})
);
});
self.addEventListener("fetch", (event) => {
// Only call event.respondWith() if this is a navigation request
// for an HTML page.
if (event.request.mode === "navigate") {
event.respondWith(
(async () => {
try {
// First, try to use the navigation preload response if it's
// supported.
const preloadResponse = await event.preloadResponse;
if (preloadResponse) {
return preloadResponse;
}
// Always try the network first.
const networkResponse = await fetch(event.request);
return networkResponse;
} catch (error) {
// catch is only triggered if an exception is thrown, which is
// likely due to a network error.
// If fetch() returns a valid HTTP response with a response code in
// the 4xx or 5xx range, the catch() will NOT be called.
console.log("Fetch failed; returning offline page instead.", error);
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(OFFLINE_URL);
return cachedResponse;
}
})()
);
}
});