Skip to content

Instantly share code, notes, and snippets.

@uglow
Created August 17, 2017 06:32
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 uglow/8351268fa5339d3ffbf0a0891f34dc3d to your computer and use it in GitHub Desktop.
Save uglow/8351268fa5339d3ffbf0a0891f34dc3d to your computer and use it in GitHub Desktop.
importScripts('workbox-sw.prod.v1.3.0.js');
const workbox = new WorkboxSW();
const cacheFirstStrategy = workbox.strategies.cacheFirst();
const networkFirstStrategy = workbox.strategies.networkFirst({networkTimeoutSeconds: 10});
// Go to the network first for APIs, then to the cache
workbox.router.registerRoute('http*://*/api/*', networkFirstStrategy, 'GET');
// Cache the external fonts
workbox.router.registerRoute('https://fonts.gstatic.com/*', cacheFirstStrategy);
// Cache the ionicons.woff2?v... file (querystring prevents cache-hit)
workbox.router.registerRoute('/assets/fonts/*', cacheFirstStrategy);
// The precache array will be populated by workbox-cli. See package.json
workbox.precache([
// ... list of static files here
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment