Skip to content
This repository was archived by the owner on Feb 5, 2022. It is now read-only.

Commit 26ab913

Browse files
committed
Moved sw into www
1 parent 12c6f31 commit 26ab913

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
dist/
22
!www/favicon.ico
3-
www/
3+
www/assets/
4+
www/build/
5+
www/index.html
6+
www/manifest.json
7+
www/robots.txt
48

59
*~
610
*.sw[mnpcod]

www/sw.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.0/workbox-sw.js');
2+
3+
// your custom service worker code
4+
self.workbox.routing.registerRoute(
5+
/\.(?:png|gif|jpg|jpeg|svg)$/,
6+
workbox.strategies.cacheFirst({
7+
cacheName: 'images',
8+
plugins: [
9+
new workbox.expiration.Plugin({
10+
maxEntries: 60,
11+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
12+
}),
13+
],
14+
}),
15+
);
16+
17+
self.workbox.routing.registerRoute(
18+
/\.(?:js|css)$/,
19+
workbox.strategies.staleWhileRevalidate({
20+
cacheName: 'static-resources',
21+
}),
22+
);
23+
24+
workbox.routing.registerRoute(
25+
new RegExp('/api/'),
26+
workbox.strategies.staleWhileRevalidate({
27+
plugins: [
28+
new workbox.broadcastUpdate.Plugin('api-updates')
29+
]
30+
})
31+
);
32+
33+
self.addEventListener('message', (event) => {
34+
if (!event.data){
35+
return;
36+
}
37+
38+
switch (event.data) {
39+
case 'skipWaiting':
40+
self.skipWaiting();
41+
break;
42+
default:
43+
// NOOP
44+
break;
45+
}
46+
});
47+
48+
self.addEventListener('install', (event) => {
49+
self.skipWaiting();
50+
})
51+
52+
self.workbox.precaching.precacheAndRoute([]);

0 commit comments

Comments
 (0)