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

Commit b03601a

Browse files
committed
Moved back into src folder
1 parent b792c8c commit b03601a

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/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([]);

stencil.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports.config = {
1919
{
2020
type: 'www',
2121
serviceWorker: {
22-
swSrc: 'assets/sw.js'
22+
swSrc: 'src/sw.js'
2323
}
2424
}
2525
],

0 commit comments

Comments
 (0)