1 | import { WorkboxPlugin } from 'workbox-core/types.js';
|
2 | import { Strategy, StrategyOptions } from 'workbox-strategies/Strategy.js';
|
3 | import { StrategyHandler } from 'workbox-strategies/StrategyHandler.js';
|
4 | import './_version.js';
|
5 | interface PrecacheStrategyOptions extends StrategyOptions {
|
6 | fallbackToNetwork?: boolean;
|
7 | }
|
8 | /**
|
9 | * A {@link workbox-strategies.Strategy} implementation
|
10 | * specifically designed to work with
|
11 | * {@link workbox-precaching.PrecacheController}
|
12 | * to both cache and fetch precached assets.
|
13 | *
|
14 | * Note: an instance of this class is created automatically when creating a
|
15 | * `PrecacheController`; it's generally not necessary to create this yourself.
|
16 | *
|
17 | * @extends workbox-strategies.Strategy
|
18 | * @memberof workbox-precaching
|
19 | */
|
20 | declare class PrecacheStrategy extends Strategy {
|
21 | private readonly _fallbackToNetwork;
|
22 | static readonly defaultPrecacheCacheabilityPlugin: WorkboxPlugin;
|
23 | static readonly copyRedirectedCacheableResponsesPlugin: WorkboxPlugin;
|
24 | /**
|
25 | *
|
26 | * @param {Object} [options]
|
27 | * @param {string} [options.cacheName] Cache name to store and retrieve
|
28 | * requests. Defaults to the cache names provided by
|
29 | * {@link workbox-core.cacheNames}.
|
30 | * @param {Array<Object>} [options.plugins] {@link https://developers.google.com/web/tools/workbox/guides/using-plugins|Plugins}
|
31 | * to use in conjunction with this caching strategy.
|
32 | * @param {Object} [options.fetchOptions] Values passed along to the
|
33 | * {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters|init}
|
34 | * of all fetch() requests made by this strategy.
|
35 | * @param {Object} [options.matchOptions] The
|
36 | * {@link https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions|CacheQueryOptions}
|
37 | * for any `cache.match()` or `cache.put()` calls made by this strategy.
|
38 | * @param {boolean} [options.fallbackToNetwork=true] Whether to attempt to
|
39 | * get the response from the network if there's a precache miss.
|
40 | */
|
41 | constructor(options?: PrecacheStrategyOptions);
|
42 | /**
|
43 | * @private
|
44 | * @param {Request|string} request A request to run this strategy for.
|
45 | * {workbox-strategies.StrategyHandler} handler The event that
|
46 | * triggered the request.
|
47 | * Promise<Response>}
{ |
48 | */
|
49 | _handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
50 | _handleFetch(request: Request, handler: StrategyHandler): Promise<Response>;
|
51 | _handleInstall(request: Request, handler: StrategyHandler): Promise<Response>;
|
52 | /**
|
53 | * This method is complex, as there a number of things to account for:
|
54 | *
|
55 | * The `plugins` array can be set at construction, and/or it might be added to
|
56 | * to at any time before the strategy is used.
|
57 | *
|
58 | * At the time the strategy is used (i.e. during an `install` event), there
|
59 | * needs to be at least one plugin that implements `cacheWillUpdate` in the
|
60 | * array, other than `copyRedirectedCacheableResponsesPlugin`.
|
61 | *
|
62 | * - If this method is called and there are no suitable `cacheWillUpdate`
|
63 | * plugins, we need to add `defaultPrecacheCacheabilityPlugin`.
|
64 | *
|
65 | * - If this method is called and there is exactly one `cacheWillUpdate`, then
|
66 | * we don't have to do anything (this might be a previously added
|
67 | * `defaultPrecacheCacheabilityPlugin`, or it might be a custom plugin).
|
68 | *
|
69 | * - If this method is called and there is more than one `cacheWillUpdate`,
|
70 | * then we need to check if one is `defaultPrecacheCacheabilityPlugin`. If so,
|
71 | * we need to remove it. (This situation is unlikely, but it could happen if
|
72 | * the strategy is used multiple times, the first without a `cacheWillUpdate`,
|
73 | * and then later on after manually adding a custom `cacheWillUpdate`.)
|
74 | *
|
75 | * See https://github.com/GoogleChrome/workbox/issues/2737 for more context.
|
76 | *
|
77 | * @private
|
78 | */
|
79 | _useDefaultCacheabilityPluginIfNeeded(): void;
|
80 | }
|
81 | export { PrecacheStrategy };
|