-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
52 lines (43 loc) · 1.27 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
49
50
51
52
// service-worker.js
// set names for both precache & runtime cache
workbox.core.setCacheNameDetails({
prefix: 'nick-maltbie',
suffix: 'v1',
precache: 'precache',
runtime: 'runtime-cache'
});
// let Service Worker take control of pages ASAP
workbox.skipWaiting();
workbox.clientsClaim();
// let Workbox handle our precache list
workbox.precaching.precacheAndRoute(self.__precacheManifest);
// use `networkFirst` strategy for `*.html`, like all my posts
workbox.routing.registerRoute(
/\.html$/,
workbox.strategies.networkFirst()
);
// use `cacheFirst` strategy for icons
workbox.routing.registerRoute(
/\.ico$/,
workbox.strategies.cacheFirst()
);
// use `cacheFirst` strategy for images
workbox.routing.registerRoute(
/assets\/(projects|icons|imgs)/,
workbox.strategies.cacheFirst()
);
// use `networkFirst` strategy for scripts
workbox.routing.registerRoute(
/assets\/scripts\/\.js$/,
workbox.strategies.networkFirst()
);
// use `networkFirst` strategy for style sheets
workbox.routing.registerRoute(
/\.css$/,
workbox.strategies.networkFirst()
);
// third party files
workbox.routing.registerRoute(
/^https?:\/\/nickmaltbie.com/,
workbox.strategies.staleWhileRevalidate()
);