diff --git a/packages/workbox/index.js b/packages/workbox/index.js index bd85732a..6353efa2 100755 --- a/packages/workbox/index.js +++ b/packages/workbox/index.js @@ -57,17 +57,13 @@ function getOptions (moduleOptions) { modifyUrlPrefix: { '': fixUrl(publicPath) }, + offline: true, _runtimeCaching: [ // Cache all _nuxt resources at runtime // They are hashed by webpack so are safe to loaded by cacheFirst handler { urlPattern: fixUrl(publicPath + '/.*'), handler: 'cacheFirst' - }, - // Cache other routes if offline - { - urlPattern: fixUrl(routerBase + '/.*'), - handler: 'networkFirst' } ], runtimeCaching: [] @@ -75,6 +71,14 @@ function getOptions (moduleOptions) { const options = defaultsDeep({}, this.options.workbox, moduleOptions, defaults) + // Optionally cache other routes for offline + if (options.offline) { + defaults._runtimeCaching.push({ + urlPattern: fixUrl(routerBase + '/.*'), + handler: 'networkFirst' + }) + } + return options }