-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice-worker.js
48 lines (39 loc) · 1.19 KB
/
service-worker.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
importScripts('assets/js/workbox-sw.js')
if (workbox) {
// ref: https://developers.google.com/web/tools/workbox/guides/get-started
// ref: http://taobaofed.org/blog/2018/08/08/workbox3/
console.log(`Yay! Workbox is loaded 🎉`)
// workbox.precaching.precacheAndRoute([
// '/assets/js/av-min.js',
// ])
workbox.routing.registerRoute(
new RegExp('.*\.html$'),
new workbox.strategies.NetworkFirst()
)
workbox.routing.registerRoute(
new RegExp('.*\.(?:js|css|ttf|woff|woff2|eot|svg|png|jpg)$'),
new workbox.strategies.CacheFirst()
)
workbox.routing.registerRoute(
'/assets/js/script.js',
new workbox.strategies.StaleWhileRevalidate()
)
workbox.routing.registerRoute(
'/service-worker.js',
new workbox.strategies.StaleWhileRevalidate()
)
workbox.routing.registerRoute(
'/assets/js/script.css',
new workbox.strategies.StaleWhileRevalidate()
)
workbox.routing.registerRoute(
new RegExp('https://cdnjs\.cloudflare\.com/'),
new workbox.strategies.StaleWhileRevalidate()
)
workbox.routing.registerRoute(
new RegExp('https://i\.loli\.net/'),
new workbox.strategies.CacheFirst({
cacheName: 'blog:img'
})
)
}