Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/GDGToulouse/devfest-theme-hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorigor <ilaborie@gmail.com>2020-02-19 09:37:00 +0300
committerigor <ilaborie@gmail.com>2020-02-19 09:37:00 +0300
commit6388fa56a34824da7cec262f46ac28b64371b961 (patch)
tree8c6a63d09017b6a93db36afb6f516efff3535064
parentfa912793ac05640d6528d1a587a7c9c26b0f9034 (diff)
Update Service Worker
-rw-r--r--static/sw.js29
1 files changed, 29 insertions, 0 deletions
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);