[Vuejs]-How can I cache an external java-script file with GenerateSW and workbox

0👍

Workbox’s RegExp routes will only match cross-origin requests if the pattern provided matches starting with the first character of the URL. There are more details about this behavior in the documentation.

urlPattern actually does support the same callback-based approached mentioned elsewhere in the docs, and I think that ends up being clearer than RegExps for most use cases:

new WorkboxPlugin.GenerateSW({
  runtimeCaching: [{
    handler: 'StaleWhileRevalidate',
    method: 'GET',
    urlPattern: ({ request }) => request.destination === 'script',
    options: {
      cacheName: 'javascript'
    }
  }]
})]

Leave a comment