Skip to content

Commit

Permalink
chore: improve offline page handling and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Feb 8, 2019
1 parent 5fc3d66 commit 263dce6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/workbox/templates/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ workbox.precaching.precacheAndRoute(<%= JSON.stringify(options.preCaching, null,

<% if (options.offlinePage) { %>
// Register router handler for offlinePage
workbox.routing.registerRoute(new RegExp('/.*'), ({event}) => {
workbox.routing.registerRoute(new RegExp('<%= options.pagesURLPattern %>'), ({event}) => {
return workbox.strategies.networkOnly().handle({event})
.catch(() => caches.match('<%= options.offlinePage %>'))
})<% } %>
Expand Down
3 changes: 2 additions & 1 deletion test/__snapshots__/pwa.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Array [
"fixture/dist/icons",
"fixture/dist/icons/index.html",
"fixture/dist/index.html",
"fixture/dist/offline.html",
]
`;

Expand Down Expand Up @@ -103,7 +104,7 @@ workbox.routing.registerRoute(new RegExp('https://google.com/.*'), workbox.strat
workbox.routing.registerRoute(new RegExp('/_nuxt/(?!.*(__webpack_hmr|hot-update))'), workbox.strategies.cacheFirst ({}), 'GET')
// Register router handler for offlinePage
workbox.routing.registerRoute(new RegExp('/.*'), ({event}) => {
workbox.routing.registerRoute(new RegExp('^/(?!.*(__webpack_hmr|hot-update))'), ({event}) => {
return workbox.strategies.networkOnly().handle({event})
.catch(() => caches.match('/offline.html'))
})
Expand Down
8 changes: 8 additions & 0 deletions test/fixture/static/offline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Offline</title>
</head>
<body>
<h1>Website is Offline :(</h1>
</body>
</html>

0 comments on commit 263dce6

Please sign in to comment.