Skip to content

Commit 76de33c

Browse files
gerardo-rodriguezpi0
authored andcommittedApr 2, 2018
feat(worbox): add offline option for making it optional (#59)
Make all-inclusive NetworkFirst route registration optional. Fixes #24.
1 parent 0c99ab9 commit 76de33c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed
 

Diff for: ‎packages/workbox/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,28 @@ function getOptions (moduleOptions) {
5757
modifyUrlPrefix: {
5858
'': fixUrl(publicPath)
5959
},
60+
offline: true,
6061
_runtimeCaching: [
6162
// Cache all _nuxt resources at runtime
6263
// They are hashed by webpack so are safe to loaded by cacheFirst handler
6364
{
6465
urlPattern: fixUrl(publicPath + '/.*'),
6566
handler: 'cacheFirst'
66-
},
67-
// Cache other routes if offline
68-
{
69-
urlPattern: fixUrl(routerBase + '/.*'),
70-
handler: 'networkFirst'
7167
}
7268
],
7369
runtimeCaching: []
7470
}
7571

7672
const options = defaultsDeep({}, this.options.workbox, moduleOptions, defaults)
7773

74+
// Optionally cache other routes for offline
75+
if (options.offline) {
76+
defaults._runtimeCaching.push({
77+
urlPattern: fixUrl(routerBase + '/.*'),
78+
handler: 'networkFirst'
79+
})
80+
}
81+
7882
return options
7983
}
8084

0 commit comments

Comments
 (0)
Please sign in to comment.