-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
81 lines (75 loc) · 2.27 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
/*
Copyright (c) 2023 Parking Miru Web Engine By Karin Vitoonkijvanit
*** Unauthorized modification of files in Parking Miru Web Engine
shall not be held liable for any damages or errors. and
It is a disruption of Parking Miru Web Engine's system. ***
*/
const CACHE_NAME = "Parking-Miru-2.0.1";
const OFFLINE_URL = "offline.html";
const assets = [
"/",
"/index.html",
"/dashboard.html",
"/smartdashboard.html",
"/UATsmartdashboard.html",
"/offline.html",
// css
"/css/style.css",
"/css/mobile.css",
// js
"/js/app.js",
"/js/clockEN.js",
"/js/loader.js",
"/js/NotiText.js",
"/js/ParkingNum.js",
"/js/scollText.js",
"/js/Titles.js",
"/js/wow.min.js",
// img
"/img/logoTNIWhite.png",
"/img/ParkingMiru.png",
"/img/ParkingMiruIcon.png",
"/img/ring-resize-white-36.svg",
"/img/TakahashiB.png",
"/img/TNICyberWeb.png",
"/img/Transparent.png",
"/img/TurnLeft.png",
];
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;
}
})()
);
}
});