From 2a20c44338ab40b497348b8374ead1ee42e440a8 Mon Sep 17 00:00:00 2001 From: Noel Schnierer Date: Wed, 4 Nov 2020 21:09:28 +0100 Subject: [PATCH] fix: fonts not cached by service worker (#2338) --- src/service-worker.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/service-worker.js b/src/service-worker.js index 14da5bd2..b84e88f6 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -36,3 +36,12 @@ workbox.routing.registerNavigationRoute( blacklist: [/^\/_/, /\/[^/?]+\.[^/]+$/], }, ); + +// Cache relevant font files +workbox.routing.registerRoute( + new RegExp("/(fonts.css|.+.(ttf|woff2|otf))"), + new workbox.strategies.StaleWhileRevalidate({ + cacheName: "fonts", + plugins: [new workbox.expiration.Plugin({ maxEntries: 10 })], + }), +);