forked from veracode/example-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsw.js
More file actions
67 lines (63 loc) · 1.81 KB
/
sw.js
File metadata and controls
67 lines (63 loc) · 1.81 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
if (location.href.includes('howdz.xyz')) {
importScripts('https://cdn.staticfile.org/workbox-sw/7.0.0/workbox-sw.js')
workbox.setConfig({
debug: false,
});
console.log('sw.js is load by CDN!')
} else {
importScripts('./workbox/workbox-sw.js')
workbox.setConfig({
debug: false,
modulePathPrefix: './workbox/'
});
console.log('sw.js is load by local!')
}
// Cache css/js/font.
workbox.routing.registerRoute(
({ request }) => request.destination === 'style' || request.destination === 'script' || request.destination === 'font',
new workbox.strategies.CacheFirst({
cacheName: 'css-js-font',
plugins: [
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [200],
}),
new workbox.expiration.ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
}),
]
})
);
// Cache image.
workbox.routing.registerRoute(
({ request }) => request.destination === 'image',
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'image',
plugins: [
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [200],
}),
new workbox.expiration.ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
})
]
})
)
// Cache video
workbox.routing.registerRoute(
({ request }) => request.destination === 'video',
new workbox.strategies.CacheFirst({
cacheName: 'video',
plugins: [
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [200],
}),
new workbox.expiration.ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
}),
new workbox.rangeRequests.RangeRequestsPlugin()
]
})
)