Skip to content
Permalink
Browse files
feat(workbox): offlineStrategy
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 e377436cedf7fc88288889a1021dfe2855e783b4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
@@ -25,6 +25,7 @@ module.exports = {

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

@@ -56,7 +56,7 @@ function getOptions (moduleOptions) {
if (options.offline && !options.offlinePage) {
options.runtimeCaching.push({
urlPattern: options.pagesURLPattern,
handler: 'NetworkFirst'
handler: options.offlineStrategy
})
}

@@ -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 %>'))
})<% } %>

@@ -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'))
})
@@ -5,7 +5,7 @@
<nuxt-link
v-for="p in ['Foo', 'Bar', 'Baz']"
:key="p"
:to="'/' + p"
:to="'/' + p.toLowerCase()"
>
{{ p }}
</nuxt-link>
@@ -0,0 +1,5 @@
<template>
<main>
You are on page: {{ $route.path }}
</main>
</template>

0 comments on commit e377436

Please sign in to comment.