serwist
Version:
A Swiss Army knife for service workers.
61 lines • 2.18 kB
TypeScript
import type { StrategyOptions } from "./Strategy.js";
import { Strategy } from "./Strategy.js";
import type { StrategyHandler } from "./StrategyHandler.js";
export interface NetworkFirstOptions extends StrategyOptions {
/**
* If set, any network requests that fail to respond within the timeout will fallback to the cache.
*/
networkTimeoutSeconds?: number;
}
/**
* An implementation of the [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 {@linkcode SerwistError} exception.
*/
export declare class NetworkFirst extends Strategy {
private readonly _networkTimeoutSeconds;
/**
* @param options
* This option can be used to combat
* "[lie-fi](https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi)"
* scenarios.
*/
constructor(options?: NetworkFirstOptions);
/**
* @private
* @param request A request to run this strategy for.
* @param handler The event that triggered the request.
* @returns
*/
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
/**
* @param options
* @returns
* @private
*/
private _getTimeoutPromise;
/**
* @param options
* @param options.timeoutId
* @param options.request
* @param options.logs A reference to the logs Array.
* @param options.event
* @returns
*
* @private
*/
_getNetworkPromise({ timeoutId, request, logs, handler, }: {
request: Request;
logs: any[];
timeoutId?: number;
handler: StrategyHandler;
}): Promise<Response | undefined>;
}
//# sourceMappingURL=NetworkFirst.d.ts.map