Skip to content

Commit

Permalink
feat(worbox): add offline option for making it optional (#59)
Browse files Browse the repository at this point in the history
Make all-inclusive NetworkFirst route registration optional.

Fixes #24.
  • Loading branch information
gerardo-rodriguez authored and pi0 committed Apr 2, 2018
1 parent 0c99ab9 commit 76de33c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/workbox/index.js
Expand Up @@ -57,24 +57,28 @@ function getOptions (moduleOptions) {
modifyUrlPrefix: { modifyUrlPrefix: {
'': fixUrl(publicPath) '': fixUrl(publicPath)
}, },
offline: true,
_runtimeCaching: [ _runtimeCaching: [
// Cache all _nuxt resources at runtime // Cache all _nuxt resources at runtime
// They are hashed by webpack so are safe to loaded by cacheFirst handler // They are hashed by webpack so are safe to loaded by cacheFirst handler
{ {
urlPattern: fixUrl(publicPath + '/.*'), urlPattern: fixUrl(publicPath + '/.*'),
handler: 'cacheFirst' handler: 'cacheFirst'
},
// Cache other routes if offline
{
urlPattern: fixUrl(routerBase + '/.*'),
handler: 'networkFirst'
} }
], ],
runtimeCaching: [] runtimeCaching: []
} }


const options = defaultsDeep({}, this.options.workbox, moduleOptions, defaults) 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 return options
} }


Expand Down

0 comments on commit 76de33c

Please sign in to comment.