forked from Azgaar/Fantasy-Map-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
95 lines (85 loc) · 2.47 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
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; // in seconds
registerRoute(
({request}) => request.mode === "navigate",
new NetworkFirst({
networkTimeoutSeconds: 15,
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: [
new CacheableResponsePlugin({statuses: [0, 200]}),
new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: 30 * DAY})
]
})
);
registerRoute(
({request}) => request.destination === "style",
new CacheFirst({
cacheName: "fmg-stylesheets",
plugins: [
new CacheableResponsePlugin({statuses: [0, 200]}),
new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: 30 * DAY})
]
})
);
registerRoute(
({request, url}) => request.destination === "script" && url.pathname.endsWith("min.js"),
new CacheFirst({
cacheName: "fmg-libs",
plugins: [
new CacheableResponsePlugin({statuses: [0, 200]}),
new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: 30 * DAY})
]
})
);
registerRoute(
new RegExp(".json$"),
new CacheFirst({
cacheName: "fmg-json",
plugins: [
new CacheableResponsePlugin({statuses: [0, 200]}),
new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: 30 * DAY})
]
})
);
registerRoute(
({request}) => request.destination === "image",
new CacheFirst({
cacheName: "fmg-images",
plugins: [
new CacheableResponsePlugin({statuses: [0, 200]}),
new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: 60 * DAY})
]
})
);
registerRoute(
new RegExp(".svg$"),
new CacheFirst({
cacheName: "fmg-charges",
plugins: [
new CacheableResponsePlugin({statuses: [0, 200]}),
new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: 60 * DAY})
]
})
);
registerRoute(
({request}) => request.destination === "font",
new CacheFirst({
cacheName: "fmg-fonts",
plugins: [
new CacheableResponsePlugin({statuses: [0, 200]}),
new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: 60 * DAY})
]
})
);