From 6388fa56a34824da7cec262f46ac28b64371b961 Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 19 Feb 2020 07:37:00 +0100 Subject: Update Service Worker --- static/sw.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/static/sw.js b/static/sw.js index 13a0ae5..46b66eb 100644 --- a/static/sw.js +++ b/static/sw.js @@ -3,6 +3,9 @@ importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox if (workbox) { console.log("Yay! Workbox is loaded 🎉"); + // Cache HTML + workbox.routing.registerRoute(/\.html$/, new workbox.strategies.NetworkFirst()); + // Cache JS workbox.routing.registerRoute(/\.js$/, new workbox.strategies.NetworkFirst()); @@ -23,6 +26,32 @@ if (workbox) { }) ); + // Cache the Google Fonts stylesheets with a stale-while-revalidate strategy. + workbox.routing.registerRoute( + /^https:\/\/fonts\.googleapis\.com/, + new workbox.strategies.StaleWhileRevalidate({ + cacheName: 'google-fonts-stylesheets', + }), + ); + + // Cache the underlying font files with a cache-first strategy for 1 year. + workbox.routing.registerRoute( + /^https:\/\/fonts\.gstatic\.com/, + new workbox.strategies.CacheFirst({ + cacheName: 'google-fonts-webfonts', + plugins: [ + new workbox.cacheableResponse.Plugin({ + statuses: [0, 200], + }), + new workbox.expiration.Plugin({ + maxAgeSeconds: 60 * 60 * 24 * 365, + maxEntries: 30, + }), + ], + }), + ); + + // Workbox injection point workbox.precaching.precacheAndRoute(self.__WB_MANIFEST); -- cgit v1.2.3