-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsw.js
67 lines (62 loc) · 1.83 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
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0-beta.0/workbox-sw.js');
// Uncomment for debugging
// workbox.core.setLogLevel(workbox.core.LOG_LEVELS.debug);
workbox.routing.registerRoute(
/^https:\/\/((\w+)\.googleapis\.com|www\.googletagmanager\.com|code\.getmdl\.io)\/.+$/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'google-cache',
plugins: [
// Allow opaque responses
new workbox.cacheableResponse.Plugin({
statuses: [0, 200] // YOLO
}),
],
})
);
workbox.routing.registerRoute(
// Cache immutable files forever
/^https:\/\/roadtrip-api\./,
// Use the cache if it's available
workbox.strategies.cacheFirst({
cacheName: 'api-cache',
plugins: [
new workbox.expiration.Plugin({
// Cache for a maximum of 30 days
maxAgeSeconds: 30 * 24 * 60 * 60,
})
],
})
);
workbox.routing.registerRoute(
// Cache immutable files forever
/^https:\/\/[^.]+\.wikipedia\.org\//,
// Use the cache if it's available
workbox.strategies.cacheFirst({
cacheName: 'wiki-cache',
plugins: [
new workbox.expiration.Plugin({
// Cache for a maximum of 2 days
maxAgeSeconds: 2 * 24 * 60 * 60,
})
],
})
);
workbox.routing.registerRoute(
// Prefer the network but if it doesn't respond within 1 seconds,
// fallback to a doc if we have a cached version that is max
// 10 days old.
// Basically that means that the schedule should load offline for the
// duration of the conference
/(\/|\.html|\.js|\.css)$/,
// Use the network unless things are slow
workbox.strategies.networkFirst({
cacheName: 'doc-cache',
networkTimeoutSeconds: 1,
plugins: [
new workbox.expiration.Plugin({
// Cache for a maximum of 10 days
maxAgeSeconds: 10 * 24 * 60 * 60,
})
],
})
);