forked from Azgaar/Fantasy-Map-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
81 lines (70 loc) · 1.98 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
importScripts("https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js");
const {Route, registerRoute} = workbox.routing;
const {CacheFirst, NetworkFirst} = workbox.strategies;
const {CacheableResponsePlugin} = workbox.cacheableResponse;
const {ExpirationPlugin} = workbox.expiration;
const DAY = 24 * 60 * 60;
const getPolitics = ({entries, days}) => {
return [
new CacheableResponsePlugin({statuses: [0, 200]}),
new ExpirationPlugin({maxEntries: entries, maxAgeSeconds: days * DAY})
];
};
registerRoute(
({request}) => request.mode === "navigate",
new NetworkFirst({
networkTimeoutSeconds: 3,
cacheName: "fmg-html",
plugins: [new CacheableResponsePlugin({statuses: [0, 200]})]
})
);
registerRoute(
({request, url}) =>
request.destination === "script" && !url.pathname.endsWith("min.js") && !url.pathname.includes("versioning.js"),
new CacheFirst({
cacheName: "fmg-scripts",
plugins: getPolitics({entries: 100, days: 30})
})
);
registerRoute(
({request}) => request.destination === "style",
new CacheFirst({
cacheName: "fmg-stylesheets",
plugins: getPolitics({entries: 100, days: 30})
})
);
registerRoute(
({request, url}) => request.destination === "script" && url.pathname.endsWith("min.js"),
new CacheFirst({
cacheName: "fmg-libs",
plugins: getPolitics({entries: 100, days: 30})
})
);
registerRoute(
new RegExp(".json$"),
new CacheFirst({
cacheName: "fmg-json",
plugins: getPolitics({entries: 100, days: 30})
})
);
registerRoute(
({request}) => request.destination === "image",
new CacheFirst({
cacheName: "fmg-images",
plugins: getPolitics({entries: 1000, days: 30})
})
);
registerRoute(
new RegExp(".svg$"),
new CacheFirst({
cacheName: "fmg-charges",
plugins: getPolitics({entries: 1000, days: 30})
})
);
registerRoute(
({request}) => request.destination === "font",
new CacheFirst({
cacheName: "fmg-fonts",
plugins: getPolitics({entries: 200, days: 30})
})
);