|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
815 bytes
|
| Line | |
|---|
| 1 | import {Strategy} from 'workbox-strategies/Strategy.js';
|
|---|
| 2 |
|
|---|
| 3 | import './_version.js';
|
|---|
| 4 |
|
|---|
| 5 | export interface WarmStrategyCacheOptions {
|
|---|
| 6 | urls: Array<string>;
|
|---|
| 7 | strategy: Strategy;
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | // Give TypeScript the correct global.
|
|---|
| 11 | declare let self: ServiceWorkerGlobalScope;
|
|---|
| 12 |
|
|---|
| 13 | /**
|
|---|
| 14 | * @memberof workbox-recipes
|
|---|
| 15 |
|
|---|
| 16 | * @param {Object} options
|
|---|
| 17 | * @param {string[]} options.urls Paths to warm the strategy's cache with
|
|---|
| 18 | * @param {Strategy} options.strategy Strategy to use
|
|---|
| 19 | */
|
|---|
| 20 | function warmStrategyCache(options: WarmStrategyCacheOptions): void {
|
|---|
| 21 | self.addEventListener('install', (event) => {
|
|---|
| 22 | const done = options.urls.map(
|
|---|
| 23 | (path) =>
|
|---|
| 24 | options.strategy.handleAll({
|
|---|
| 25 | event,
|
|---|
| 26 | request: new Request(path),
|
|---|
| 27 | })[1],
|
|---|
| 28 | );
|
|---|
| 29 |
|
|---|
| 30 | event.waitUntil(Promise.all(done));
|
|---|
| 31 | });
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | export {warmStrategyCache};
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.