Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active January 24, 2019 16:29
Show Gist options
  • Save daliborgogic/2b335e7441207f61fc7856dd6d9b1e7c to your computer and use it in GitHub Desktop.
Save daliborgogic/2b335e7441207f61fc7856dd6d9b1e7c to your computer and use it in GitHub Desktop.
sw.js
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js')
if (workbox) {
console.log(`Workbox is loaded`)
workbox.setConfig({ debug: true })
workbox.core.setLogLevel(workbox.core.LOG_LEVELS.log)
workbox.core.setCacheNameDetails({
prefix: 'localhost',
suffix: 'v1',
precache: 'localhost-precache',
runtime: 'localhost-runtime'
})
workbox.routing.registerRoute(new RegExp('/_nuxt/.*'), workbox.strategies.staleWhileRevalidate({
cacheName: 'localhost-static',
}))
workbox.routing.registerRoute(new RegExp('/.*'), workbox.strategies.networkFirst())
workbox.googleAnalytics.initialize({
parameterOverrides: {
dimension1: 'offline'
},
hitFilter: params => {
const queueTimeInSeconds = Math.round(params.get('qt') / 1000)
params.set('metric1', queueTimeInSeconds)
}
})
} else {
console.log(`Workbox didn't load.`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment