From fb6e9538bc3f25239fd3c515f956274bc04229c2 Mon Sep 17 00:00:00 2001 From: willyb321 Date: Mon, 29 Apr 2019 06:44:03 +1000 Subject: [PATCH] change service worker caching --- src/sw.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/sw.js b/src/sw.js index 9a724691..4b7bb5c7 100644 --- a/src/sw.js +++ b/src/sw.js @@ -7,8 +7,8 @@ if (workbox) { workbox.routing.registerNavigationRoute('/index.html'); workbox.routing.registerRoute( - new RegExp('/(.*?)'), - workbox.strategies.staleWhileRevalidate({ + /\.(?:png|jpg|jpeg|svg|gif)$/, + new workbox.strategies.CacheFirst({ plugins: [ new workbox.cacheableResponse.Plugin({ statuses: [0, 200] @@ -17,9 +17,16 @@ if (workbox) { }) ); + workbox.routing.registerRoute( + /\.(?:js|css)$/, + new workbox.strategies.StaleWhileRevalidate({ + cacheName: 'static-resources', + }) + ); + workbox.routing.registerRoute( new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'), - workbox.strategies.cacheFirst({ + new workbox.strategies.CacheFirst({ cacheName: 'google-fonts', plugins: [ new workbox.expiration.Plugin({ @@ -31,12 +38,6 @@ if (workbox) { ] }) ); - - try { - workbox.googleAnalytics.initialize(); - } catch (e) { - console.log('Probably an ad-blocker'); - } } else { console.log('Boo! Workbox didn\'t load 😬'); }