@serwist/strategies 9.0.0-preview.3 → 9.0.0-preview.4
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 +11 -12
- 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 +17 -18
- package/dist/StaleWhileRevalidate.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/CacheFirst.ts +2 -4
- package/src/CacheOnly.ts +2 -4
- package/src/NetworkFirst.ts +11 -12
- package/src/NetworkOnly.ts +9 -13
- package/src/StaleWhileRevalidate.ts +17 -18
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
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)"
|
|
@@ -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
4
|
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);
|
|
@@ -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,cAAM,oBAAqB,SAAQ,QAAQ;IACzC;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,OAAO,GAAE,eAAoB;IAUzC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsD7E;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
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.4",
|
|
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.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"rollup": "4.9.6",
|
|
37
37
|
"typescript": "5.4.0-dev.20240206",
|
|
38
|
-
"@serwist/constants": "9.0.0-preview.
|
|
38
|
+
"@serwist/constants": "9.0.0-preview.4"
|
|
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
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)"
|
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
17
|
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 = {}) {
|