Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wreszelewski/85fefda3d19c5cc18dac78398e664394 to your computer and use it in GitHub Desktop.
Save wreszelewski/85fefda3d19c5cc18dac78398e664394 to your computer and use it in GitHub Desktop.
sw.js
importScripts('https://unpkg.com/[email protected]/build/importScripts/workbox-sw.dev.v0.0.2.js');
importScripts('https://unpkg.com/[email protected]/build/importScripts/workbox-google-analytics.prod.v1.0.0.js');
const workboxSW = new WorkboxSW({clientsClaim: true});
workbox.googleAnalytics.initialize();
workboxSW.router.registerRoute(
/\.?!(html)$/,
workboxSW.strategies.cacheFirst({
cacheName: 'assets',
cacheExpiration : {
maxEntries: 20,
maxAgeSeconds: 7 * 24 * 60 * 60
},
cacheableResponse: {statuses: [0, 200]}
})
);
workboxSW.router.registerRoute(
/\.html$/,
workboxSW.strategies.networkFirst({networkTimeoutSeconds: 3})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment