Skip to content

Commit e377436

Browse files
author
pooya parsa
committed
feat(workbox): offlineStrategy
BREAKING CHANGE: default changed from NetworkOnly to NetworkFirst when offlinePage is enabled
1 parent 4fef661 commit e377436

File tree

6 files changed

+10
-4
lines changed

6 files changed

+10
-4
lines changed

packages/workbox/lib/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525

2626
// Offline
2727
offline: true,
28+
offlineStrategy: 'NetworkFirst',
2829
offlinePage: null,
2930
offlineAssets: [],
3031

packages/workbox/lib/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function getOptions (moduleOptions) {
5656
if (options.offline && !options.offlinePage) {
5757
options.runtimeCaching.push({
5858
urlPattern: options.pagesURLPattern,
59-
handler: 'NetworkFirst'
59+
handler: options.offlineStrategy
6060
})
6161
}
6262

packages/workbox/templates/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ workbox.precaching.precacheAndRoute(<%= JSON.stringify(options.preCaching, null,
6363
<% if (options.offlinePage) { %>
6464
// Register router handler for offlinePage
6565
workbox.routing.registerRoute(new RegExp('<%= options.pagesURLPattern %>'), ({event}) => {
66-
return new workbox.strategies.NetworkOnly().handle({event})
66+
return new workbox.strategies.<%= options.offlineStrategy %>().handle({event})
6767
.catch(() => caches.match('<%= options.offlinePage %>'))
6868
})<% } %>
6969

test/__snapshots__/pwa.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ workbox.routing.registerRoute(new RegExp('/_nuxt/(?!.*(__webpack_hmr|hot-update)
110110
111111
// Register router handler for offlinePage
112112
workbox.routing.registerRoute(new RegExp('/(?!.*(__webpack_hmr|hot-update))'), ({event}) => {
113-
return new workbox.strategies.NetworkOnly().handle({event})
113+
return new workbox.strategies.NetworkFirst().handle({event})
114114
.catch(() => caches.match('/offline.html'))
115115
})
116116

test/fixture/layouts/default.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<nuxt-link
66
v-for="p in ['Foo', 'Bar', 'Baz']"
77
:key="p"
8-
:to="'/' + p"
8+
:to="'/' + p.toLowerCase()"
99
>
1010
{{ p }}
1111
</nuxt-link>

test/fixture/pages/_page.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<main>
3+
You are on page: {{ $route.path }}
4+
</main>
5+
</template>

0 commit comments

Comments
 (0)