1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import { RouteHandlerObject, RouteHandlerCallbackOptions, WorkboxPlugin } from 'workbox-core/types.js';
- import './_version.js';
- interface StaleWhileRevalidateOptions {
- cacheName?: string;
- plugins?: WorkboxPlugin[];
- fetchOptions?: RequestInit;
- matchOptions?: CacheQueryOptions;
- }
- /**
- * An implementation of a
- * [stale-while-revalidate]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#stale-while-revalidate}
- * request strategy.
- *
- * Resources are requested from both the cache and the network in parallel.
- * The strategy will respond with the cached version if available, otherwise
- * wait for the network response. The cache is updated with the network response
- * with each successful request.
- *
- * By default, this strategy will cache responses with a 200 status code as
- * well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
- * Opaque responses are cross-origin requests where the response doesn't
- * support [CORS]{@link https://enable-cors.org/}.
- *
- * If the network request fails, and there is no cache match, this will throw
- * a `WorkboxError` exception.
- *
- * @memberof module:workbox-strategies
- */
- declare class StaleWhileRevalidate implements RouteHandlerObject {
- private readonly _cacheName;
- private readonly _plugins;
- private readonly _fetchOptions?;
- private readonly _matchOptions?;
- /**
- * @param {Object} options
- * @param {string} options.cacheName Cache name to store and retrieve
- * requests. Defaults to cache names provided by
- * [workbox-core]{@link module: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 all fetch() requests made by this strategy.
- * @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
- */
- constructor(options?: StaleWhileRevalidateOptions);
- /**
- * This method will perform a request strategy and follows an API that
- * will work with the
- * [Workbox Router]{@link module:workbox-routing.Router}.
- *
- * @param {Object} options
- * @param {Request|string} options.request A request to run this strategy for.
- * @param {Event} [options.event] The event that triggered the request.
- * @return {Promise<Response>}
- */
- handle({ event, request }: RouteHandlerCallbackOptions): Promise<Response>;
- /**
- * @param {Object} options
- * @param {Request} options.request
- * @param {Event} [options.event]
- * @return {Promise<Response>}
- *
- * @private
- */
- _getFromNetwork({ request, event }: {
- request: Request;
- event?: ExtendableEvent;
- }): Promise<Response>;
- }
- export { StaleWhileRevalidate };
|