warmStrategyCache.js 542 B

123456789101112131415161718
  1. import './_version.js';
  2. /**
  3. * @memberof workbox-recipes
  4. * @param {Object} options
  5. * @param {string[]} options.urls Paths to warm the strategy's cache with
  6. * @param {Strategy} options.strategy Strategy to use
  7. */
  8. function warmStrategyCache(options) {
  9. self.addEventListener('install', (event) => {
  10. const done = options.urls.map((path) => options.strategy.handleAll({
  11. event,
  12. request: new Request(path),
  13. })[1]);
  14. event.waitUntil(Promise.all(done));
  15. });
  16. }
  17. export { warmStrategyCache };