Last active
January 24, 2019 16:29
-
-
Save daliborgogic/2b335e7441207f61fc7856dd6d9b1e7c to your computer and use it in GitHub Desktop.
sw.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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