@serwist/strategies 9.0.0-preview.1 → 9.0.0-preview.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CacheFirst.d.ts +2 -3
- package/dist/CacheFirst.d.ts.map +1 -1
- package/dist/CacheOnly.d.ts +2 -3
- package/dist/CacheOnly.d.ts.map +1 -1
- package/dist/NetworkFirst.d.ts +12 -14
- package/dist/NetworkFirst.d.ts.map +1 -1
- package/dist/NetworkOnly.d.ts +9 -12
- package/dist/NetworkOnly.d.ts.map +1 -1
- package/dist/StaleWhileRevalidate.d.ts +18 -20
- package/dist/StaleWhileRevalidate.d.ts.map +1 -1
- package/dist/Strategy.d.ts +1 -2
- package/dist/Strategy.d.ts.map +1 -1
- package/dist/StrategyHandler.d.ts +1 -2
- package/dist/StrategyHandler.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/package.json +4 -4
- package/src/CacheFirst.ts +2 -4
- package/src/CacheOnly.ts +2 -4
- package/src/NetworkFirst.ts +12 -15
- package/src/NetworkOnly.ts +9 -13
- package/src/StaleWhileRevalidate.ts +18 -21
- package/src/Strategy.ts +1 -3
- package/src/StrategyHandler.ts +15 -16
package/dist/CacheFirst.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Strategy } from "./Strategy.js";
|
|
2
2
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
3
3
|
/**
|
|
4
|
-
* An implementation of
|
|
4
|
+
* An implementation of the [cache first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-first-falling-back-to-network)
|
|
5
5
|
* request strategy.
|
|
6
6
|
*
|
|
7
7
|
* A cache first strategy is useful for assets that have been revisioned,
|
|
@@ -11,7 +11,7 @@ import type { StrategyHandler } from "./StrategyHandler.js";
|
|
|
11
11
|
* If the network request fails, and there is no cache match, this will throw
|
|
12
12
|
* a `SerwistError` exception.
|
|
13
13
|
*/
|
|
14
|
-
declare class CacheFirst extends Strategy {
|
|
14
|
+
export declare class CacheFirst extends Strategy {
|
|
15
15
|
/**
|
|
16
16
|
* @private
|
|
17
17
|
* @param request A request to run this strategy for.
|
|
@@ -20,5 +20,4 @@ declare class CacheFirst extends Strategy {
|
|
|
20
20
|
*/
|
|
21
21
|
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
22
22
|
}
|
|
23
|
-
export { CacheFirst };
|
|
24
23
|
//# sourceMappingURL=CacheFirst.d.ts.map
|
package/dist/CacheFirst.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheFirst.d.ts","sourceRoot":"","sources":["../src/CacheFirst.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;;;;GAUG;AACH,
|
|
1
|
+
{"version":3,"file":"CacheFirst.d.ts","sourceRoot":"","sources":["../src/CacheFirst.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,QAAQ;IACtC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsD7E"}
|
package/dist/CacheOnly.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Strategy } from "./Strategy.js";
|
|
2
2
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
3
3
|
/**
|
|
4
|
-
* An implementation of
|
|
4
|
+
* An implementation of the [cache only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-only)
|
|
5
5
|
* request strategy.
|
|
6
6
|
*
|
|
7
7
|
* This class is useful if you want to take advantage of any Serwist plugin.
|
|
8
8
|
*
|
|
9
9
|
* If there is no cache match, this will throw a `SerwistError` exception.
|
|
10
10
|
*/
|
|
11
|
-
declare class CacheOnly extends Strategy {
|
|
11
|
+
export declare class CacheOnly extends Strategy {
|
|
12
12
|
/**
|
|
13
13
|
* @private
|
|
14
14
|
* @param request A request to run this strategy for.
|
|
@@ -17,5 +17,4 @@ declare class CacheOnly extends Strategy {
|
|
|
17
17
|
*/
|
|
18
18
|
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
19
19
|
}
|
|
20
|
-
export { CacheOnly };
|
|
21
20
|
//# sourceMappingURL=CacheOnly.d.ts.map
|
package/dist/CacheOnly.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheOnly.d.ts","sourceRoot":"","sources":["../src/CacheOnly.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"CacheOnly.d.ts","sourceRoot":"","sources":["../src/CacheOnly.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,QAAQ;IACrC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CA4B7E"}
|
package/dist/NetworkFirst.d.ts
CHANGED
|
@@ -7,21 +7,20 @@ export interface NetworkFirstOptions extends StrategyOptions {
|
|
|
7
7
|
*/
|
|
8
8
|
networkTimeoutSeconds?: number;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
* An implementation of a [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
|
|
12
|
-
* request strategy.
|
|
13
|
-
*
|
|
14
|
-
* By default, this strategy will cache responses with a 200 status code as
|
|
15
|
-
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
16
|
-
* Opaque responses are are cross-origin requests where the response doesn't
|
|
17
|
-
* support [CORS](https://enable-cors.org/).
|
|
18
|
-
*
|
|
19
|
-
* If the network request fails, and there is no cache match, this will throw
|
|
20
|
-
* a `SerwistError` exception.
|
|
21
|
-
*/
|
|
22
|
-
declare class NetworkFirst extends Strategy {
|
|
10
|
+
export declare class NetworkFirst extends Strategy {
|
|
23
11
|
private readonly _networkTimeoutSeconds;
|
|
24
12
|
/**
|
|
13
|
+
* An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
|
|
14
|
+
* request strategy.
|
|
15
|
+
*
|
|
16
|
+
* By default, this strategy will cache responses with a 200 status code as
|
|
17
|
+
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
18
|
+
* Opaque responses are are cross-origin requests where the response doesn't
|
|
19
|
+
* support [CORS](https://enable-cors.org/).
|
|
20
|
+
*
|
|
21
|
+
* If the network request fails, and there is no cache match, this will throw
|
|
22
|
+
* a `SerwistError` exception.
|
|
23
|
+
*
|
|
25
24
|
* @param options
|
|
26
25
|
* This option can be used to combat
|
|
27
26
|
* "[lie-fi](https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi)"
|
|
@@ -58,5 +57,4 @@ declare class NetworkFirst extends Strategy {
|
|
|
58
57
|
handler: StrategyHandler;
|
|
59
58
|
}): Promise<Response | undefined>;
|
|
60
59
|
}
|
|
61
|
-
export { NetworkFirst };
|
|
62
60
|
//# sourceMappingURL=NetworkFirst.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkFirst.d.ts","sourceRoot":"","sources":["../src/NetworkFirst.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED
|
|
1
|
+
{"version":3,"file":"NetworkFirst.d.ts","sourceRoot":"","sources":["../src/NetworkFirst.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAEhD;;;;;;;;;;;;;;;;OAgBG;gBACS,OAAO,GAAE,mBAAwB;IAsB7C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgE5E;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;;;;;;;;OASG;IACG,kBAAkB,CAAC,EACvB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAqClC"}
|
package/dist/NetworkOnly.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import type { StrategyOptions } from "./Strategy.js";
|
|
2
2
|
import { Strategy } from "./Strategy.js";
|
|
3
3
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
4
|
-
interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" | "matchOptions"> {
|
|
4
|
+
export interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" | "matchOptions"> {
|
|
5
5
|
/**
|
|
6
6
|
* If set, any network requests that fail to respond within the timeout will result in a network error.
|
|
7
7
|
*/
|
|
8
8
|
networkTimeoutSeconds?: number;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
* An implementation of a [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
|
|
12
|
-
* request strategy.
|
|
13
|
-
*
|
|
14
|
-
* This class is useful if you want to take advantage of any Serwist plugin.
|
|
15
|
-
*
|
|
16
|
-
* If the network request fails, this will throw a `SerwistError` exception.
|
|
17
|
-
*/
|
|
18
|
-
declare class NetworkOnly extends Strategy {
|
|
10
|
+
export declare class NetworkOnly extends Strategy {
|
|
19
11
|
private readonly _networkTimeoutSeconds;
|
|
20
12
|
/**
|
|
13
|
+
* An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
|
|
14
|
+
* request strategy.
|
|
15
|
+
*
|
|
16
|
+
* This class is useful if you want to take advantage of any Serwist plugin.
|
|
17
|
+
*
|
|
18
|
+
* If the network request fails, this will throw a `SerwistError` exception.
|
|
19
|
+
*
|
|
21
20
|
* @param options
|
|
22
21
|
*/
|
|
23
22
|
constructor(options?: NetworkOnlyOptions);
|
|
@@ -29,6 +28,4 @@ declare class NetworkOnly extends Strategy {
|
|
|
29
28
|
*/
|
|
30
29
|
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
31
30
|
}
|
|
32
|
-
export { NetworkOnly };
|
|
33
|
-
export type { NetworkOnlyOptions };
|
|
34
31
|
//# sourceMappingURL=NetworkOnly.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkOnly.d.ts","sourceRoot":"","sources":["../src/NetworkOnly.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,
|
|
1
|
+
{"version":3,"file":"NetworkOnly.d.ts","sourceRoot":"","sources":["../src/NetworkOnly.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,cAAc,CAAC;IAC7F;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,qBAAa,WAAY,SAAQ,QAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAEhD;;;;;;;;;OASG;gBACS,OAAO,GAAE,kBAAuB;IAM5C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CA+C7E"}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import type { StrategyOptions } from "./Strategy.js";
|
|
2
2
|
import { Strategy } from "./Strategy.js";
|
|
3
3
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
4
|
-
|
|
5
|
-
* An implementation of a
|
|
6
|
-
* [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
|
|
7
|
-
* request strategy.
|
|
8
|
-
*
|
|
9
|
-
* Resources are requested from both the cache and the network in parallel.
|
|
10
|
-
* The strategy will respond with the cached version if available, otherwise
|
|
11
|
-
* wait for the network response. The cache is updated with the network response
|
|
12
|
-
* with each successful request.
|
|
13
|
-
*
|
|
14
|
-
* By default, this strategy will cache responses with a 200 status code as
|
|
15
|
-
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
16
|
-
* Opaque responses are cross-origin requests where the response doesn't
|
|
17
|
-
* support [CORS](https://enable-cors.org/).
|
|
18
|
-
*
|
|
19
|
-
* If the network request fails, and there is no cache match, this will throw
|
|
20
|
-
* a `SerwistError` exception.
|
|
21
|
-
*/
|
|
22
|
-
declare class StaleWhileRevalidate extends Strategy {
|
|
4
|
+
export declare class StaleWhileRevalidate extends Strategy {
|
|
23
5
|
/**
|
|
6
|
+
* An implementation of the
|
|
7
|
+
* [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
|
|
8
|
+
* request strategy.
|
|
9
|
+
*
|
|
10
|
+
* Resources are requested from both the cache and the network in parallel.
|
|
11
|
+
* The strategy will respond with the cached version if available, otherwise
|
|
12
|
+
* wait for the network response. The cache is updated with the network response
|
|
13
|
+
* with each successful request.
|
|
14
|
+
*
|
|
15
|
+
* By default, this strategy will cache responses with a 200 status code as
|
|
16
|
+
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
17
|
+
* Opaque responses are cross-origin requests where the response doesn't
|
|
18
|
+
* support [CORS](https://enable-cors.org/).
|
|
19
|
+
*
|
|
20
|
+
* If the network request fails, and there is no cache match, this will throw
|
|
21
|
+
* a `SerwistError` exception.
|
|
22
|
+
*
|
|
24
23
|
* @param options
|
|
25
24
|
*/
|
|
26
25
|
constructor(options?: StrategyOptions);
|
|
@@ -32,5 +31,4 @@ declare class StaleWhileRevalidate extends Strategy {
|
|
|
32
31
|
*/
|
|
33
32
|
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
34
33
|
}
|
|
35
|
-
export { StaleWhileRevalidate };
|
|
36
34
|
//# sourceMappingURL=StaleWhileRevalidate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StaleWhileRevalidate.d.ts","sourceRoot":"","sources":["../src/StaleWhileRevalidate.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D
|
|
1
|
+
{"version":3,"file":"StaleWhileRevalidate.d.ts","sourceRoot":"","sources":["../src/StaleWhileRevalidate.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D,qBAAa,oBAAqB,SAAQ,QAAQ;IAChD;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,OAAO,GAAE,eAAoB;IAUzC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsD7E"}
|
package/dist/Strategy.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface StrategyOptions {
|
|
|
27
27
|
* fetching and cache logic, which will ensure all relevant cache, cache options,
|
|
28
28
|
* fetch options and plugins are used (per the current strategy instance).
|
|
29
29
|
*/
|
|
30
|
-
declare abstract class Strategy implements RouteHandlerObject {
|
|
30
|
+
export declare abstract class Strategy implements RouteHandlerObject {
|
|
31
31
|
cacheName: string;
|
|
32
32
|
plugins: SerwistPlugin[];
|
|
33
33
|
fetchOptions?: RequestInit;
|
|
@@ -80,5 +80,4 @@ declare abstract class Strategy implements RouteHandlerObject {
|
|
|
80
80
|
_getResponse(handler: StrategyHandler, request: Request, event: ExtendableEvent): Promise<Response>;
|
|
81
81
|
_awaitComplete(responseDone: Promise<Response>, handler: StrategyHandler, request: Request, event: ExtendableEvent): Promise<void>;
|
|
82
82
|
}
|
|
83
|
-
export { Strategy };
|
|
84
83
|
//# sourceMappingURL=Strategy.d.ts.map
|
package/dist/Strategy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Strategy.d.ts","sourceRoot":"","sources":["../src/Strategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG/F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"Strategy.d.ts","sourceRoot":"","sources":["../src/Strategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG/F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED;;;;;GAKG;AACH,8BAAsB,QAAS,YAAW,kBAAkB;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAEjC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAErG;;;;;;;;;OASG;gBACS,OAAO,GAAE,eAAoB;IAOzC;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,sBAAsB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAKvE;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,sBAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAsBrF,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAyCnG,cAAc,CAAC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAqCzI"}
|
|
@@ -6,7 +6,7 @@ import type { Strategy } from "./Strategy.js";
|
|
|
6
6
|
* and keeps track of when the strategy is "done" (i.e. all added `event.waitUntil()` promises
|
|
7
7
|
* have resolved).
|
|
8
8
|
*/
|
|
9
|
-
declare class StrategyHandler {
|
|
9
|
+
export declare class StrategyHandler {
|
|
10
10
|
/**
|
|
11
11
|
* The request the strategy is performing (passed to the strategy's
|
|
12
12
|
* `handle()` or `handleAll()` method).
|
|
@@ -184,5 +184,4 @@ declare class StrategyHandler {
|
|
|
184
184
|
*/
|
|
185
185
|
_ensureResponseSafeToCache(response: Response): Promise<Response | undefined>;
|
|
186
186
|
}
|
|
187
|
-
export { StrategyHandler };
|
|
188
187
|
//# sourceMappingURL=StrategyHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StrategyHandler.d.ts","sourceRoot":"","sources":["../src/StrategyHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAiB,aAAa,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAYtH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"StrategyHandler.d.ts","sourceRoot":"","sources":["../src/StrategyHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAiB,aAAa,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAYtH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B;;;OAGG;IACI,OAAO,EAAG,OAAO,CAAC;IACzB;;;;;OAKG;IACI,GAAG,CAAC,EAAE,GAAG,CAAC;IACjB;;OAEG;IACI,KAAK,EAAE,eAAe,CAAC;IAC9B;;;;;;OAMG;IACI,MAAM,CAAC,EAAE,GAAG,CAAC;IAEpB,OAAO,CAAC,UAAU,CAA+B;IAEjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAiB;IACzD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAoC;IAEpE;;;;;;;;;OASG;gBACS,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,sBAAsB;IA4B/D;;;;;;;;;;;;OAYG;IACG,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAyElD;;;;;;;;;OASG;IACG,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAS7D;;;;;;;;;;;OAWG;IACG,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IA+BjE;;;;;;;;;;;;;;OAcG;IACG,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IA8FtE;;;;;;;;;;OAUG;IACG,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAqB7E;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO;IAS5D;;;;;;;;;;;;OAYG;IACG,YAAY,CAAC,CAAC,SAAS,MAAM,WAAW,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3I;;;;;;;;OAQG;IACF,gBAAgB,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAgBnG;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAK7C;;;;;;;;OAQG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAOlC;;;OAGG;IACH,OAAO,IAAI,IAAI;IAIf;;;;;;;OAOG;IACG,0BAA0B,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAuCpF"}
|
package/dist/index.js
CHANGED
|
@@ -141,10 +141,6 @@ class StrategyHandler {
|
|
|
141
141
|
method: effectiveRequest.method
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
const vary = response.headers.get("Vary");
|
|
145
|
-
if (vary) {
|
|
146
|
-
logger.debug(`The response for ${getFriendlyURL(effectiveRequest.url)} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`);
|
|
147
|
-
}
|
|
148
144
|
}
|
|
149
145
|
if (!response) {
|
|
150
146
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -163,12 +159,18 @@ class StrategyHandler {
|
|
|
163
159
|
}
|
|
164
160
|
const { cacheName, matchOptions } = this._strategy;
|
|
165
161
|
const cache = await self.caches.open(cacheName);
|
|
162
|
+
if (process.env.NODE_ENV !== "production") {
|
|
163
|
+
const vary = response.headers.get("Vary");
|
|
164
|
+
if (vary && matchOptions?.ignoreVary !== true) {
|
|
165
|
+
logger.debug(`The response for ${getFriendlyURL(effectiveRequest.url)} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
166
168
|
const hasCacheUpdateCallback = this.hasCallback("cacheDidUpdate");
|
|
167
169
|
const oldResponse = hasCacheUpdateCallback ? await cacheMatchIgnoreParams(cache, effectiveRequest.clone(), [
|
|
168
170
|
"__WB_REVISION__"
|
|
169
171
|
], matchOptions) : null;
|
|
170
172
|
if (process.env.NODE_ENV !== "production") {
|
|
171
|
-
logger.debug(`Updating the '${cacheName}' cache with a new Response
|
|
173
|
+
logger.debug(`Updating the '${cacheName}' cache with a new Response for ${getFriendlyURL(effectiveRequest.url)}.`);
|
|
172
174
|
}
|
|
173
175
|
try {
|
|
174
176
|
await cache.put(effectiveRequest, hasCacheUpdateCallback ? responseToCache.clone() : responseToCache);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/strategies",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A service worker helper library implementing common caching strategies.",
|
|
6
6
|
"files": [
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"./package.json": "./package.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@serwist/core": "9.0.0-preview.
|
|
33
|
+
"@serwist/core": "9.0.0-preview.10"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"rollup": "4.9.6",
|
|
37
|
-
"typescript": "5.4.0-dev.
|
|
38
|
-
"@serwist/constants": "9.0.0-preview.
|
|
37
|
+
"typescript": "5.4.0-dev.20240206",
|
|
38
|
+
"@serwist/constants": "9.0.0-preview.10"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"typescript": ">=5.0.0"
|
package/src/CacheFirst.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { StrategyHandler } from "./StrategyHandler.js";
|
|
|
13
13
|
import { messages } from "./utils/messages.js";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* An implementation of
|
|
16
|
+
* An implementation of the [cache first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-first-falling-back-to-network)
|
|
17
17
|
* request strategy.
|
|
18
18
|
*
|
|
19
19
|
* A cache first strategy is useful for assets that have been revisioned,
|
|
@@ -23,7 +23,7 @@ import { messages } from "./utils/messages.js";
|
|
|
23
23
|
* If the network request fails, and there is no cache match, this will throw
|
|
24
24
|
* a `SerwistError` exception.
|
|
25
25
|
*/
|
|
26
|
-
class CacheFirst extends Strategy {
|
|
26
|
+
export class CacheFirst extends Strategy {
|
|
27
27
|
/**
|
|
28
28
|
* @private
|
|
29
29
|
* @param request A request to run this strategy for.
|
|
@@ -85,5 +85,3 @@ class CacheFirst extends Strategy {
|
|
|
85
85
|
return response;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
export { CacheFirst };
|
package/src/CacheOnly.ts
CHANGED
|
@@ -13,14 +13,14 @@ import type { StrategyHandler } from "./StrategyHandler.js";
|
|
|
13
13
|
import { messages } from "./utils/messages.js";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* An implementation of
|
|
16
|
+
* An implementation of the [cache only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-only)
|
|
17
17
|
* request strategy.
|
|
18
18
|
*
|
|
19
19
|
* This class is useful if you want to take advantage of any Serwist plugin.
|
|
20
20
|
*
|
|
21
21
|
* If there is no cache match, this will throw a `SerwistError` exception.
|
|
22
22
|
*/
|
|
23
|
-
class CacheOnly extends Strategy {
|
|
23
|
+
export class CacheOnly extends Strategy {
|
|
24
24
|
/**
|
|
25
25
|
* @private
|
|
26
26
|
* @param request A request to run this strategy for.
|
|
@@ -56,5 +56,3 @@ class CacheOnly extends Strategy {
|
|
|
56
56
|
return response;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
export { CacheOnly };
|
package/src/NetworkFirst.ts
CHANGED
|
@@ -21,22 +21,21 @@ export interface NetworkFirstOptions extends StrategyOptions {
|
|
|
21
21
|
networkTimeoutSeconds?: number;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
* An implementation of a [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
|
|
26
|
-
* request strategy.
|
|
27
|
-
*
|
|
28
|
-
* By default, this strategy will cache responses with a 200 status code as
|
|
29
|
-
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
30
|
-
* Opaque responses are are cross-origin requests where the response doesn't
|
|
31
|
-
* support [CORS](https://enable-cors.org/).
|
|
32
|
-
*
|
|
33
|
-
* If the network request fails, and there is no cache match, this will throw
|
|
34
|
-
* a `SerwistError` exception.
|
|
35
|
-
*/
|
|
36
|
-
class NetworkFirst extends Strategy {
|
|
24
|
+
export class NetworkFirst extends Strategy {
|
|
37
25
|
private readonly _networkTimeoutSeconds: number;
|
|
38
26
|
|
|
39
27
|
/**
|
|
28
|
+
* An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
|
|
29
|
+
* request strategy.
|
|
30
|
+
*
|
|
31
|
+
* By default, this strategy will cache responses with a 200 status code as
|
|
32
|
+
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
33
|
+
* Opaque responses are are cross-origin requests where the response doesn't
|
|
34
|
+
* support [CORS](https://enable-cors.org/).
|
|
35
|
+
*
|
|
36
|
+
* If the network request fails, and there is no cache match, this will throw
|
|
37
|
+
* a `SerwistError` exception.
|
|
38
|
+
*
|
|
40
39
|
* @param options
|
|
41
40
|
* This option can be used to combat
|
|
42
41
|
* "[lie-fi](https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi)"
|
|
@@ -227,5 +226,3 @@ class NetworkFirst extends Strategy {
|
|
|
227
226
|
return response;
|
|
228
227
|
}
|
|
229
228
|
}
|
|
230
|
-
|
|
231
|
-
export { NetworkFirst };
|
package/src/NetworkOnly.ts
CHANGED
|
@@ -13,25 +13,24 @@ import { Strategy } from "./Strategy.js";
|
|
|
13
13
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
14
14
|
import { messages } from "./utils/messages.js";
|
|
15
15
|
|
|
16
|
-
interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" | "matchOptions"> {
|
|
16
|
+
export interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" | "matchOptions"> {
|
|
17
17
|
/**
|
|
18
18
|
* If set, any network requests that fail to respond within the timeout will result in a network error.
|
|
19
19
|
*/
|
|
20
20
|
networkTimeoutSeconds?: number;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
* An implementation of a [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
|
|
25
|
-
* request strategy.
|
|
26
|
-
*
|
|
27
|
-
* This class is useful if you want to take advantage of any Serwist plugin.
|
|
28
|
-
*
|
|
29
|
-
* If the network request fails, this will throw a `SerwistError` exception.
|
|
30
|
-
*/
|
|
31
|
-
class NetworkOnly extends Strategy {
|
|
23
|
+
export class NetworkOnly extends Strategy {
|
|
32
24
|
private readonly _networkTimeoutSeconds: number;
|
|
33
25
|
|
|
34
26
|
/**
|
|
27
|
+
* An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
|
|
28
|
+
* request strategy.
|
|
29
|
+
*
|
|
30
|
+
* This class is useful if you want to take advantage of any Serwist plugin.
|
|
31
|
+
*
|
|
32
|
+
* If the network request fails, this will throw a `SerwistError` exception.
|
|
33
|
+
*
|
|
35
34
|
* @param options
|
|
36
35
|
*/
|
|
37
36
|
constructor(options: NetworkOnlyOptions = {}) {
|
|
@@ -94,6 +93,3 @@ class NetworkOnly extends Strategy {
|
|
|
94
93
|
return response;
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
|
-
|
|
98
|
-
export { NetworkOnly };
|
|
99
|
-
export type { NetworkOnlyOptions };
|
|
@@ -14,26 +14,25 @@ import type { StrategyHandler } from "./StrategyHandler.js";
|
|
|
14
14
|
import { cacheOkAndOpaquePlugin } from "./plugins/cacheOkAndOpaquePlugin.js";
|
|
15
15
|
import { messages } from "./utils/messages.js";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
* An implementation of a
|
|
19
|
-
* [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
|
|
20
|
-
* request strategy.
|
|
21
|
-
*
|
|
22
|
-
* Resources are requested from both the cache and the network in parallel.
|
|
23
|
-
* The strategy will respond with the cached version if available, otherwise
|
|
24
|
-
* wait for the network response. The cache is updated with the network response
|
|
25
|
-
* with each successful request.
|
|
26
|
-
*
|
|
27
|
-
* By default, this strategy will cache responses with a 200 status code as
|
|
28
|
-
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
29
|
-
* Opaque responses are cross-origin requests where the response doesn't
|
|
30
|
-
* support [CORS](https://enable-cors.org/).
|
|
31
|
-
*
|
|
32
|
-
* If the network request fails, and there is no cache match, this will throw
|
|
33
|
-
* a `SerwistError` exception.
|
|
34
|
-
*/
|
|
35
|
-
class StaleWhileRevalidate extends Strategy {
|
|
17
|
+
export class StaleWhileRevalidate extends Strategy {
|
|
36
18
|
/**
|
|
19
|
+
* An implementation of the
|
|
20
|
+
* [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
|
|
21
|
+
* request strategy.
|
|
22
|
+
*
|
|
23
|
+
* Resources are requested from both the cache and the network in parallel.
|
|
24
|
+
* The strategy will respond with the cached version if available, otherwise
|
|
25
|
+
* wait for the network response. The cache is updated with the network response
|
|
26
|
+
* with each successful request.
|
|
27
|
+
*
|
|
28
|
+
* By default, this strategy will cache responses with a 200 status code as
|
|
29
|
+
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
30
|
+
* Opaque responses are cross-origin requests where the response doesn't
|
|
31
|
+
* support [CORS](https://enable-cors.org/).
|
|
32
|
+
*
|
|
33
|
+
* If the network request fails, and there is no cache match, this will throw
|
|
34
|
+
* a `SerwistError` exception.
|
|
35
|
+
*
|
|
37
36
|
* @param options
|
|
38
37
|
*/
|
|
39
38
|
constructor(options: StrategyOptions = {}) {
|
|
@@ -107,5 +106,3 @@ class StaleWhileRevalidate extends Strategy {
|
|
|
107
106
|
return response;
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
|
-
|
|
111
|
-
export { StaleWhileRevalidate };
|
package/src/Strategy.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface StrategyOptions {
|
|
|
39
39
|
* fetching and cache logic, which will ensure all relevant cache, cache options,
|
|
40
40
|
* fetch options and plugins are used (per the current strategy instance).
|
|
41
41
|
*/
|
|
42
|
-
abstract class Strategy implements RouteHandlerObject {
|
|
42
|
+
export abstract class Strategy implements RouteHandlerObject {
|
|
43
43
|
cacheName: string;
|
|
44
44
|
plugins: SerwistPlugin[];
|
|
45
45
|
fetchOptions?: RequestInit;
|
|
@@ -201,5 +201,3 @@ abstract class Strategy implements RouteHandlerObject {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
|
|
205
|
-
export { Strategy };
|
package/src/StrategyHandler.ts
CHANGED
|
@@ -30,7 +30,7 @@ function toRequest(input: RequestInfo) {
|
|
|
30
30
|
* and keeps track of when the strategy is "done" (i.e. all added `event.waitUntil()` promises
|
|
31
31
|
* have resolved).
|
|
32
32
|
*/
|
|
33
|
-
class StrategyHandler {
|
|
33
|
+
export class StrategyHandler {
|
|
34
34
|
/**
|
|
35
35
|
* The request the strategy is performing (passed to the strategy's
|
|
36
36
|
* `handle()` or `handleAll()` method).
|
|
@@ -281,16 +281,6 @@ class StrategyHandler {
|
|
|
281
281
|
method: effectiveRequest.method,
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
-
|
|
285
|
-
// See https://github.com/GoogleChrome/workbox/issues/2818
|
|
286
|
-
const vary = response.headers.get("Vary");
|
|
287
|
-
if (vary) {
|
|
288
|
-
logger.debug(
|
|
289
|
-
`The response for ${getFriendlyURL(
|
|
290
|
-
effectiveRequest.url,
|
|
291
|
-
)} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`,
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
284
|
}
|
|
295
285
|
|
|
296
286
|
if (!response) {
|
|
@@ -315,6 +305,18 @@ class StrategyHandler {
|
|
|
315
305
|
const { cacheName, matchOptions } = this._strategy;
|
|
316
306
|
const cache = await self.caches.open(cacheName);
|
|
317
307
|
|
|
308
|
+
if (process.env.NODE_ENV !== "production") {
|
|
309
|
+
// See https://github.com/GoogleChrome/workbox/issues/2818
|
|
310
|
+
const vary = response.headers.get("Vary");
|
|
311
|
+
if (vary && matchOptions?.ignoreVary !== true) {
|
|
312
|
+
logger.debug(
|
|
313
|
+
`The response for ${getFriendlyURL(
|
|
314
|
+
effectiveRequest.url,
|
|
315
|
+
)} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
318
320
|
const hasCacheUpdateCallback = this.hasCallback("cacheDidUpdate");
|
|
319
321
|
const oldResponse = hasCacheUpdateCallback
|
|
320
322
|
? await cacheMatchIgnoreParams(
|
|
@@ -329,7 +331,7 @@ class StrategyHandler {
|
|
|
329
331
|
: null;
|
|
330
332
|
|
|
331
333
|
if (process.env.NODE_ENV !== "production") {
|
|
332
|
-
logger.debug(`Updating the '${cacheName}' cache with a new Response
|
|
334
|
+
logger.debug(`Updating the '${cacheName}' cache with a new Response for ${getFriendlyURL(effectiveRequest.url)}.`);
|
|
333
335
|
}
|
|
334
336
|
|
|
335
337
|
try {
|
|
@@ -379,8 +381,7 @@ class StrategyHandler {
|
|
|
379
381
|
mode,
|
|
380
382
|
request: effectiveRequest,
|
|
381
383
|
event: this.event,
|
|
382
|
-
|
|
383
|
-
params: this.params, // eslint-disable-line
|
|
384
|
+
params: this.params,
|
|
384
385
|
}),
|
|
385
386
|
);
|
|
386
387
|
}
|
|
@@ -541,5 +542,3 @@ class StrategyHandler {
|
|
|
541
542
|
return responseToCache;
|
|
542
543
|
}
|
|
543
544
|
}
|
|
544
|
-
|
|
545
|
-
export { StrategyHandler };
|