This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
70 lines (65 loc) · 1.81 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
importScripts("/precache-manifest.860d566c948c0356fc76b1c0ed8e9534.js", "https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
workbox.core.skipWaiting();
workbox.core.clientsClaim();
workbox.precaching.precacheAndRoute(self.__precacheManifest);
workbox.routing.registerNavigationRoute(
workbox.precaching.getCacheKeyForURL("/index.html")
);
workbox.routing.registerRoute(
/^https:\/\/fonts\.gstatic\.com/,
new workbox.strategies.CacheFirst({
cacheName: "google-fonts-webfonts",
plugins: []
}),
"GET"
);
workbox.routing.registerRoute(
/.js$/,
new workbox.strategies.NetworkFirst({
cacheName: "shell",
plugins: []
}),
"GET"
);
workbox.routing.registerRoute(
/^https:\/\/fonts\.googleapis\.com/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: "google-fonts-stylesheets",
plugins: []
}),
"GET"
);
workbox.routing.registerRoute(
/\.(?:png|gif|jpg|jpeg|svg)$/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: "images",
plugins: []
}),
"GET"
);
workbox.routing.registerRoute(
/content\.txt$/,
new workbox.strategies.NetworkFirst({
cacheName: "content",
plugins: []
}),
"GET"
);
self.addEventListener("install", event => {
// TODO load the list of content files to warm up in the cache here
// TODO store content in a cache that is hashed based on the webpack bundle hash,
// then delete the old cache on activate
const contentUrls = [
// "/blog/content.txt",
// "/blog/types-over-conventions/content.txt"
];
const coreUrls = ["/main.js"];
const preloadContent = caches
.open("content")
.then(cache => cache.addAll(contentUrls));
const preloadCore = caches
.open("shell")
.then(cache => cache.addAll(coreUrls));
const warmUp = Promise.all([preloadContent, preloadCore]);
return warmUp;
});