Urara-Blog/node_modules/.pnpm-store/v3/files/6b/f0cca1f4fc6289d930a63ab5af57beda7a133551fab6a20c23c6078264d6382557f09fa0222ac468d387be3ee246e1e82574c6d5e72988e5c888468f08427c
2022-08-14 01:14:53 +08:00

34 lines
815 B
Text

import {Strategy} from 'workbox-strategies/Strategy.js';
import './_version.js';
export interface WarmStrategyCacheOptions {
urls: Array<string>;
strategy: Strategy;
}
// Give TypeScript the correct global.
declare let self: ServiceWorkerGlobalScope;
/**
* @memberof workbox-recipes
* @param {Object} options
* @param {string[]} options.urls Paths to warm the strategy's cache with
* @param {Strategy} options.strategy Strategy to use
*/
function warmStrategyCache(options: WarmStrategyCacheOptions): void {
self.addEventListener('install', (event) => {
const done = options.urls.map(
(path) =>
options.strategy.handleAll({
event,
request: new Request(path),
})[1],
);
event.waitUntil(Promise.all(done));
});
}
export {warmStrategyCache};