Skip to content

Commit

Permalink
feat(workbox): offlineStrategy
Browse files Browse the repository at this point in the history
BREAKING CHANGE: default changed from NetworkOnly to NetworkFirst when offlinePage is enabled
  • Loading branch information
pooya parsa committed May 7, 2019
1 parent 4fef661 commit e377436
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/workbox/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {

// Offline
offline: true,
offlineStrategy: 'NetworkFirst',
offlinePage: null,
offlineAssets: [],

Expand Down
2 changes: 1 addition & 1 deletion packages/workbox/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function getOptions (moduleOptions) {
if (options.offline && !options.offlinePage) {
options.runtimeCaching.push({
urlPattern: options.pagesURLPattern,
handler: 'NetworkFirst'
handler: options.offlineStrategy
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/workbox/templates/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ workbox.precaching.precacheAndRoute(<%= JSON.stringify(options.preCaching, null,
<% if (options.offlinePage) { %>
// Register router handler for offlinePage
workbox.routing.registerRoute(new RegExp('<%= options.pagesURLPattern %>'), ({event}) => {
return new workbox.strategies.NetworkOnly().handle({event})
return new workbox.strategies.<%= options.offlineStrategy %>().handle({event})
.catch(() => caches.match('<%= options.offlinePage %>'))
})<% } %>

Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/pwa.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ workbox.routing.registerRoute(new RegExp('/_nuxt/(?!.*(__webpack_hmr|hot-update)
// Register router handler for offlinePage
workbox.routing.registerRoute(new RegExp('/(?!.*(__webpack_hmr|hot-update))'), ({event}) => {
return new workbox.strategies.NetworkOnly().handle({event})
return new workbox.strategies.NetworkFirst().handle({event})
.catch(() => caches.match('/offline.html'))
})
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<nuxt-link
v-for="p in ['Foo', 'Bar', 'Baz']"
:key="p"
:to="'/' + p"
:to="'/' + p.toLowerCase()"
>
{{ p }}
</nuxt-link>
Expand Down
5 changes: 5 additions & 0 deletions test/fixture/pages/_page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<main>
You are on page: {{ $route.path }}
</main>
</template>

0 comments on commit e377436

Please sign in to comment.