[test] switch to service workers

dont merge to live until can be confirmed to work well
This commit is contained in:
willyb321
2018-08-26 09:44:44 +10:00
parent afbfe3ea12
commit 0aecbbf892
7 changed files with 344 additions and 24 deletions

40
src/sw.js Normal file
View File

@@ -0,0 +1,40 @@
console.log('Hello from sw.js');
if (workbox) {
console.log('Yay! Workbox is loaded 🎉');
workbox.routing.registerRoute(
new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'),
workbox.strategies.cacheFirst({
cacheName: 'google-fonts',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 30
}),
new workbox.cacheableResponse.Plugin({
statuses: [0, 200]
})
]
})
);
workbox.routing.registerRoute(
/\.(?:png|gif|jpg|jpeg|svg)$/,
workbox.strategies.cacheFirst({
cacheName: 'images',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60 // 30 Days
})
]
})
);
workbox.routing.registerRoute(
/\.(?:js|css)$/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'static-resources'
})
);
workbox.googleAnalytics.initialize();
} else {
console.log('Boo! Workbox didn\'t load 😬');
}