Skip to content

Instantly share code, notes, and snippets.

@caraya
Last active February 27, 2018 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caraya/59fb03215c42e655691c1e39c8076fa7 to your computer and use it in GitHub Desktop.
Save caraya/59fb03215c42e655691c1e39c8076fa7 to your computer and use it in GitHub Desktop.
service worker to cache fonts
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