-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
77 lines (69 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
// load static stuff from cache but also update cache
workbox.routing.registerRoute(
/\.(?:html)/,
workbox.strategies.networkFirst({
cacheName: 'static-resources',
plugins: [
// if we later want to add a notification to reload the page when a new version of the app is
// there we can listen to this via `new BroadcastChannel('cache-update-index')`
new workbox.broadcastUpdate.Plugin('cache-update-index')
]
}),
);
workbox.routing.registerRoute(
/\.(?:js|css|png|gif|json)$/,
workbox.strategies.cacheFirst({
cacheName: 'static-resources',
}),
);
// cache the responses from have i been pwned indefinitely as they woun't update
workbox.routing.registerRoute(
'https://api.pwnedpasswords.com/range/*',
workbox.strategies.cacheFirst({
cacheName: 'pwnedpasswords-range',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 1000
}),
new workbox.cacheableResponse.Plugin({
statuses: [200],
}),
],
}),
);
workbox.routing.registerRoute(
'https://api.pwnedpasswords.com/pwnedpassword/*',
workbox.strategies.cacheFirst({
cacheName: 'pwnedpasswords-passwords',
plugins: [
new workbox.expiration.Plugin({
// only is a status code + number so we can cache a lot of these
maxEntries: 10000
}),
new workbox.cacheableResponse.Plugin({
statuses: [404, 200],
}),
],
}),
);
workbox.routing.registerRoute(
'https://media.giphy.com/*',
workbox.strategies.cacheFirst({
cacheName: 'gifs',
plugins: [
new workbox.expiration.Plugin({
// only is a status code + number so we can cache a lot of these
maxEntries: 100
}),
new workbox.cacheableResponse.Plugin({
statuses: [200],
}),
],
}),
);
// offline analytics
workbox.googleAnalytics.initialize();
workbox.precaching.precacheAndRoute(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.skipWaiting();
workbox.clientsClaim();