Last active
February 27, 2018 21:02
-
-
Save caraya/59fb03215c42e655691c1e39c8076fa7 to your computer and use it in GitHub Desktop.
service worker to cache fonts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
importScripts( | |
'https://storage.googleapis.com/workbox-cdn/releases/3.0.0-beta.0/workbox-sw.js ' | |
); | |
if (workbox) { | |
workbox.routing.registerRoute( | |
/.*\.(?:woff2,woff,ttf,otf)/, | |
workbox.strategies.cacheFirst({ | |
cacheName: 'font-cache', | |
plugins: [ | |
new workbox.expiration.Plugin({ | |
maxEntries: 10, | |
maxAgeSeconds: 30 * 24 * 60 * 60 | |
}) | |
] | |
}) | |
); | |
else { | |
console.log(`Boo! Workbox didn't load`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment