Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 1.39 KB

cache-maps.md

File metadata and controls

22 lines (18 loc) · 1.39 KB

cacheMaps option

This option allows to redirect request to a cache or another requests. Imagine your are developing your website with App-Shell pattern and you cache your app-shell as index page /. Now when user visits /something-else we need to server the same app-shell to them from the cache. It can be easily done with cacheMaps:

new OfflinePlugin({
  cacheMaps: [
    {
      match: function(requestUrl) {
        return new URL('/', location);
      },
      requestTypes: ['navigate']
    }
  ]
})

Available properties on a map object:

  • match: string | RegExp | function -- matches an URL to map to a cache. If function is specified it accepts 2 arguments: URL object of a request and Request itself as second argument. Return value of the specified function is used a new URL. It must be URL object.
  • to: string | function -- only used if match is a not a function. Each URL is matched with urlString.replace(map.match, map.to) so to option is the second argument to String#replace function being called on request url.
  • requestTypes: Array -- An array of request types this map should be used with. Could be any combination of values: 'navigate', 'same-origin', 'cross-origin'. Example: requestTypes: ['navigate', 'same-origin']