Skip to content

Instantly share code, notes, and snippets.

@thangman22
Created April 1, 2018 03:14
Show Gist options
  • Select an option

  • Save thangman22/acf88940069114775e2daca1b565f3d0 to your computer and use it in GitHub Desktop.

Select an option

Save thangman22/acf88940069114775e2daca1b565f3d0 to your computer and use it in GitHub Desktop.
importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js")
workbox.setConfig({
debug: false
})
workbox.routing.registerRoute(
new RegExp('.*(?:googleapis|gstatic)\.com.*$'),
workbox.strategies.staleWhileRevalidate(),
)
workbox.routing.registerRoute(
new RegExp('.*\.js'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'js-cache',
})
)
workbox.routing.registerRoute(
new RegExp('.*\.css'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'css-cache',
})
)
workbox.routing.registerRoute(
new RegExp('.*\.woff2'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'font-cache',
})
)
workbox.routing.registerRoute(
/\.(?:png|gif|jpg|jpeg|svg|ico)$/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'image-cache',
})
)
workbox.routing.registerRoute(
new RegExp('^((?!wp-admin|wp-login).)*$'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'page-cache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 10,
maxAgeSeconds: 7 * 24 * 60 * 60
})
]
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment