-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwabuilder-sw.js
38 lines (33 loc) · 880 Bytes
/
pwabuilder-sw.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
// This is the service worker with the Cache-first network
const CACHE = "pwabuilder-precache";
const API_CACHE = "api-cache";
importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js"
);
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
workbox.routing.registerRoute(
({ url }) => url.hostname.startsWith("karlsruhe-trash.azurewebsites.net"),
new workbox.strategies.NetworkFirst({
cacheName: API_CACHE,
plugins: [
new workbox.expiration.ExpirationPlugin({
maxEntries: 5,
}),
],
})
);
workbox.routing.registerRoute(
new RegExp("/*"),
new workbox.strategies.StaleWhileRevalidate({
cacheName: CACHE,
plugins: [
new workbox.expiration.ExpirationPlugin({
maxEntries: 50,
}),
],
})
);