From 76de33cc4f7dde9e1b930be773add3736851a95e Mon Sep 17 00:00:00 2001 From: Gerardo Rodriguez Date: Mon, 2 Apr 2018 13:26:14 -0700 Subject: [PATCH] feat(worbox): add offline option for making it optional (#59) Make all-inclusive NetworkFirst route registration optional. Fixes #24. --- packages/workbox/index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 }