Permalink
Browse files

feat: Add support of StrategyOptions to cache

  • Loading branch information...
Artur Wronski authored and pi0 committed Mar 1, 2018
1 parent d934021 commit b17bbd04dc67778004392da91841092e55847d37
Showing with 22 additions and 2 deletions.
  1. +18 −0 docs/modules/workbox.md
  2. +4 −2 packages/workbox/templates/sw.template.js
@@ -47,6 +47,24 @@ workbox: {
}
```
#### Adding custom cache [StrategyOption](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-sw.Strategies#.StrategyOptions)
```js
workbox: {
runtimeCaching: [
{
urlPattern: 'https://my-cdn.com/posts/.*',
strategyOptions: {
cacheName: 'our-cache',
cacheExpiration: {
maxEntries: 10,
maxAgeSeconds: 300
}
}
}
]
}
```
### Adding custom service worker
Create `static/custom-sw.js` file:
@@ -4,6 +4,8 @@ const workboxSW = new self.WorkboxSW(<%= JSON.stringify(options.wbOptions, null,
workboxSW.precache([])
<% options.runtimeCaching.forEach(r => { %>
workboxSW.router.registerRoute(new RegExp('<%= r.urlPattern %>'), workboxSW.strategies.<%= r.handler %>({}), '<%= r.method %>')
<% options.runtimeCaching.forEach(r => {
const strategy = JSON.stringify(r.strategyOptions || {})
%>
workboxSW.router.registerRoute(new RegExp('<%= r.urlPattern %>'), workboxSW.strategies.<%= r.handler %>(<%= strategy %>), '<%= r.method %>')
<% }) %>

0 comments on commit b17bbd0

Please sign in to comment.