-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservice-worker.js
More file actions
executable file
·39 lines (31 loc) · 1.06 KB
/
service-worker.js
File metadata and controls
executable file
·39 lines (31 loc) · 1.06 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
importScripts("/assets/js/workbox-v3.6.3/workbox-sw.js");
workbox.setConfig({modulePathPrefix: "/assets/js/workbox-v3.6.3"});
self.__precacheManifest = [{"url":"/index.html","revision":"d41d8cd98f00b204e9800998ecf8427e"}];
// service-worker.js
// set names for both precache & runtime cache
workbox.core.setCacheNameDetails({
prefix: 'alacerda',
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 images
workbox.routing.registerRoute(
/assets\/(img|icons)/,
workbox.strategies.cacheFirst()
);
// third party files
workbox.routing.registerRoute(
/^https?:\/\/cdn.staticfile.org/,
workbox.strategies.staleWhileRevalidate()
);