Skip to content

Commit

Permalink
feat(workbox): assetsURLPattern, pagesURLPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Feb 8, 2019
1 parent 67f1c3d commit 5fc3d66
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions docs/modules/workbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ Workbox takes a lot of the heavy lifting out of precaching by simplifying the AP

(String) Loads and inserts the contents of the specified file path into the service worker script, below autogenerated calls to `workbox.routing.*`. You may add as many extra calls as you want to this file.

### `assetsURLPattern`

(String/Regex) Pattern to match assets for runtime caching.

Default is auto generated based on `publicPath`. Supports CDN too.

Default: `/_nuxt/(?!.*(__webpack_hmr|hot-update))`

### `pagesURLPattern`

(String/Regex) Pattern to match pages to be offlined.

Default is auto generated based on `router.base`.

Default: `^/(?!.*(__webpack_hmr|hot-update))`

<!-- SW -->

Expand Down
2 changes: 2 additions & 0 deletions packages/workbox/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module.exports = {
runtimeCaching: [],
routingExtensions: [],
cacheAssets: true,
assetsURLPattern: undefined,
pagesURLPattern: undefined,

// Sw
swTemplate: undefined,
Expand Down
10 changes: 8 additions & 2 deletions packages/workbox/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,23 @@ function getOptions (moduleOptions) {
}

// Cache all _nuxt resources at runtime
if (!options.assetsURLPattern) {
options.assetsURLPattern = joinUrl(options.publicPath, HMRRegex)
}
if (options.cacheAssets) {
options.runtimeCaching.push({
urlPattern: joinUrl(options.publicPath, HMRRegex),
urlPattern: options.assetsURLPattern,
handler: 'cacheFirst'
})
}

// Optionally cache other routes for offline
if (!options.pagesURLPattern) {
options.pagesURLPattern = joinUrl(`^${options.routerBase}`, HMRRegex)
}
if (options.offline && !options.offlinePage) {
options.runtimeCaching.push({
urlPattern: joinUrl(`^${options.routerBase}`, HMRRegex),
urlPattern: options.pagesURLPattern,
handler: 'networkFirst'
})
}
Expand Down

0 comments on commit 5fc3d66

Please sign in to comment.