Skip to content

Commit

Permalink
feat: use better regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Feb 7, 2019
1 parent ff3d502 commit 318228e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/workbox/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const path = require('path')
const defaults = require('./defaults')
const { fixUrl, isUrl } = require('./utils')

const HMRRegex = '(?!.*(__webpack_hmr|hot-update))'

function getOptions (moduleOptions) {
const options = Object.assign({}, defaults, moduleOptions, this.options.workbox)

Expand Down Expand Up @@ -47,15 +49,15 @@ function getOptions (moduleOptions) {
// Cache all _nuxt resources at runtime
if (options.cacheAssets) {
options.runtimeCaching.push({
urlPattern: fixUrl(`${options.publicPath}/(?!.*hot-update).+`),
urlPattern: fixUrl(`${options.publicPath}/${HMRRegex}`),
handler: 'cacheFirst'
})
}

// Optionally cache other routes for offline
if (options.offline && !options.offlinePage) {
options.runtimeCaching.push({
urlPattern: fixUrl(`${options.routerBase}/.*`),
urlPattern: fixUrl(`^${options.routerBase}/${HMRRegex}`),
handler: 'networkFirst'
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/pwa.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ workbox.precaching.precacheAndRoute([], {
// Register route handlers for runtimeCaching
workbox.routing.registerRoute(new RegExp('https://google.com/.*'), workbox.strategies.cacheFirst ({}), 'GET')
workbox.routing.registerRoute(new RegExp('/_nuxt/(?!.*hot-update).+'), workbox.strategies.cacheFirst ({}), 'GET')
workbox.routing.registerRoute(new RegExp('/.*'), workbox.strategies.networkFirst ({}), 'GET')
workbox.routing.registerRoute(new RegExp('/_nuxt/(?!.*(__webpack_hmr|hot-update))'), workbox.strategies.cacheFirst ({}), 'GET')
workbox.routing.registerRoute(new RegExp('^/(?!.*(__webpack_hmr|hot-update))'), workbox.strategies.networkFirst ({}), 'GET')
"
`;

0 comments on commit 318228e

Please sign in to comment.