-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsw.js
More file actions
executable file
·45 lines (39 loc) · 1.19 KB
/
Copy pathsw.js
File metadata and controls
executable file
·45 lines (39 loc) · 1.19 KB
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
const CACHE = "klascal";
importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/7.4.1/workbox-sw.js"
);
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
// Cache images using StaleWhileRevalidate strategy
workbox.routing.registerRoute(
({ request }) => request.destination === "image",
new workbox.strategies.StaleWhileRevalidate({
cacheName: `${CACHE}-images`,
})
);
// Cache fonts using StaleWhileRevalidate strategy
workbox.routing.registerRoute(
({ request }) => request.destination === "font" || !/css2/.test(request.url),
new workbox.strategies.StaleWhileRevalidate({
cacheName: `${CACHE}-fonts`,
})
);
// Cache scripts using StaleWhileRevalidate strategy, excluding "schedule"
workbox.routing.registerRoute(
({ request }) =>
request.destination === "script" && !/schedule/.test(request.url),
new workbox.strategies.StaleWhileRevalidate({
cacheName: `${CACHE}-scripts`,
})
);
// Use NetworkFirst strategy for all other requests
workbox.routing.registerRoute(
/\/*/,
new workbox.strategies.NetworkFirst({
cacheName: CACHE,
networkTimeoutSeconds: 5,
})
);