Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created April 28, 2020 16:00
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 andreasvirkus/c0aa8767eb254a01a0d00b5376017d24 to your computer and use it in GitHub Desktop.
Save andreasvirkus/c0aa8767eb254a01a0d00b5376017d24 to your computer and use it in GitHub Desktop.
SW for vue-cli with Google's workbox
// eslint-disable-next-line no-undef
workbox.setConfig({
debug: false
})
workbox.core.skipWaiting()
workbox.precaching.precacheAndRoute([])
workbox.routing.registerRoute(
/\.(?:png|gif|jpg|jpeg|svg)$/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'images',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60 // 30 Days
})
]
})
)
workbox.routing.registerRoute(
new RegExp('^https://firestore\\.googleapis\\.com/'),
workbox.strategies.networkFirst({
cacheName: 'api'
})
)
workbox.routing.registerRoute(
new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'),
workbox.strategies.cacheFirst({
cacheName: 'googleapis',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 30
})
]
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment