mirror of https://github.com/jkjoy/sunpeiwen.git
81 lines
3.3 KiB
TypeScript
81 lines
3.3 KiB
TypeScript
import { Strategy, StrategyOptions } from './Strategy.js';
|
|
import { StrategyHandler } from './StrategyHandler.js';
|
|
import './_version.js';
|
|
export interface NetworkFirstOptions extends StrategyOptions {
|
|
networkTimeoutSeconds?: number;
|
|
}
|
|
/**
|
|
* An implementation of a
|
|
* [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
|
|
* request strategy.
|
|
*
|
|
* By default, this strategy will cache responses with a 200 status code as
|
|
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
* Opaque responses are are cross-origin requests where the response doesn't
|
|
* support [CORS](https://enable-cors.org/).
|
|
*
|
|
* If the network request fails, and there is no cache match, this will throw
|
|
* a `WorkboxError` exception.
|
|
*
|
|
* @extends workbox-strategies.Strategy
|
|
* @memberof workbox-strategies
|
|
*/
|
|
declare class NetworkFirst extends Strategy {
|
|
private readonly _networkTimeoutSeconds;
|
|
/**
|
|
* @param {Object} [options]
|
|
* @param {string} [options.cacheName] Cache name to store and retrieve
|
|
* requests. Defaults to cache names provided by
|
|
* {@link workbox-core.cacheNames}.
|
|
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
|
* to use in conjunction with this caching strategy.
|
|
* @param {Object} [options.fetchOptions] Values passed along to the
|
|
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
|
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
|
|
* `fetch()` requests made by this strategy.
|
|
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
|
* @param {number} [options.networkTimeoutSeconds] If set, any network requests
|
|
* that fail to respond within the timeout will fallback to the cache.
|
|
*
|
|
* This option can be used to combat
|
|
* "[lie-fi]{@link https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi}"
|
|
* scenarios.
|
|
*/
|
|
constructor(options?: NetworkFirstOptions);
|
|
/**
|
|
* @private
|
|
* @param {Request|string} request A request to run this strategy for.
|
|
* @param {workbox-strategies.StrategyHandler} handler The event that
|
|
* triggered the request.
|
|
* @return {Promise<Response>}
|
|
*/
|
|
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
/**
|
|
* @param {Object} options
|
|
* @param {Request} options.request
|
|
* @param {Array} options.logs A reference to the logs array
|
|
* @param {Event} options.event
|
|
* @return {Promise<Response>}
|
|
*
|
|
* @private
|
|
*/
|
|
private _getTimeoutPromise;
|
|
/**
|
|
* @param {Object} options
|
|
* @param {number|undefined} options.timeoutId
|
|
* @param {Request} options.request
|
|
* @param {Array} options.logs A reference to the logs Array.
|
|
* @param {Event} options.event
|
|
* @return {Promise<Response>}
|
|
*
|
|
* @private
|
|
*/
|
|
_getNetworkPromise({ timeoutId, request, logs, handler, }: {
|
|
request: Request;
|
|
logs: any[];
|
|
timeoutId?: number;
|
|
handler: StrategyHandler;
|
|
}): Promise<Response | undefined>;
|
|
}
|
|
export { NetworkFirst };
|