-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathservice-worker.js
40 lines (33 loc) · 1.02 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
// service-worker.js
// set names for both precache & runtime cache
workbox.core.setCacheNameDetails({
prefix: 'apiman-website',
suffix: 'v1.0',
precache: 'precache',
runtime: 'runtime-cache'
});
// let Service Worker take control of pages ASAP
workbox.core.skipWaiting();
workbox.core.clientsClaim();
// let Workbox handle our precache list
workbox.precaching.precacheAndRoute(self.__precacheManifest);
// use `NetworkFirst` strategy for html
workbox.routing.registerRoute(
/\.html$/,
new workbox.strategies.NetworkFirst()
);
// use `NetworkFirst` strategy for css and js
workbox.routing.registerRoute(
/\.(?:js|css)$/,
new workbox.strategies.NetworkFirst()
);
// use `CacheFirst` strategy for images
workbox.routing.registerRoute(
/assets\/(img|icons)/,
new workbox.strategies.CacheFirst()
);
// use `StaleWhileRevalidate` third party files
workbox.routing.registerRoute(
/^https?:\/\/(cdn.jsdelivr.net|code.jquery.com|cdnjs.cloudflare.com)/,
new workbox.strategies.StaleWhileRevalidate()
);