-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserviceworker.js
More file actions
48 lines (39 loc) · 1.07 KB
/
serviceworker.js
File metadata and controls
48 lines (39 loc) · 1.07 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
46
47
48
// Uses workbox to cache most static resources
// https://developers.google.com/web/tools/workbox/guides/get-started
importScripts(
'https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js',
)
workbox.setConfig({ debug: false })
workbox.googleAnalytics.initialize()
workbox.core.setCacheNameDetails({
prefix: 'samlau.me',
suffix: 'v1',
})
workbox.routing.registerRoute(
new RegExp('(/r/.+)$'),
new workbox.strategies.NetworkFirst(),
)
workbox.routing.registerRoute(
new RegExp('(/tweak-it.+)$'),
new workbox.strategies.NetworkFirst(),
)
workbox.routing.registerRoute(
new RegExp('(/|/projects.*|/about|/cv)$'),
new workbox.strategies.StaleWhileRevalidate(),
)
workbox.routing.registerRoute(
/\.(?:png|gif|jpg|jpeg|webp|svg)$/,
new workbox.strategies.CacheFirst({
cacheName: 'assets',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
}),
],
}),
)
workbox.routing.registerRoute(
/\.(?:js|css|pdf)$/,
new workbox.strategies.StaleWhileRevalidate(),
)