@serwist/svelte 9.0.0-preview.9 → 9.0.0
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/index.worker.d.ts +28 -12
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +48 -20
- package/package.json +8 -15
- package/src/index.worker.ts +178 -114
package/dist/index.worker.d.ts
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
/// <reference types="@sveltejs/kit" />
|
2
|
-
import type { PrecacheEntry } from "
|
3
|
-
import
|
4
|
-
|
5
|
-
export
|
6
|
-
export type StaticRevisions = {
|
2
|
+
import type { PrecacheEntry, RuntimeCaching } from "serwist";
|
3
|
+
import { base as basePath, build as immutableAssets, files as staticAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion } from "$service-worker";
|
4
|
+
export { basePath, immutableAssets, staticAssets, prerenderedRoutes, serviceWorkerVersion };
|
5
|
+
export type StaticRevisions = string | {
|
7
6
|
[url: string]: string | null;
|
8
7
|
};
|
8
|
+
export type ManifestTransform = (manifest: PrecacheEntry[]) => {
|
9
|
+
manifest: PrecacheEntry[];
|
10
|
+
warnings?: string[] | undefined;
|
11
|
+
};
|
9
12
|
export interface GetPrecacheManifestOptions {
|
10
13
|
/**
|
11
14
|
* Whether immutable assets, as in assets that are generated by
|
@@ -28,25 +31,38 @@ export interface GetPrecacheManifestOptions {
|
|
28
31
|
*/
|
29
32
|
precachePrerendered?: boolean;
|
30
33
|
/**
|
31
|
-
*
|
32
|
-
*
|
34
|
+
* A string revision used for all static assets or an object that maps
|
35
|
+
* URLs of static assets to custom revisions.
|
36
|
+
* If an URL doesn't exist in the object, `serviceWorkerVersion`
|
33
37
|
* will be used instead.
|
34
38
|
*
|
35
39
|
* This helps prevent such assets, which are unlikely to change, from
|
36
|
-
* being invalidated every time the service worker is
|
40
|
+
* being invalidated every time the service worker is rebuilt and updated.
|
37
41
|
*
|
38
|
-
* Note: you should prefix these URLs with
|
42
|
+
* Note: you should prefix these URLs with `basePath`.
|
39
43
|
*/
|
40
44
|
staticRevisions?: StaticRevisions;
|
45
|
+
/**
|
46
|
+
* One or more functions which will be applied sequentially against the
|
47
|
+
* generated manifest.
|
48
|
+
*/
|
49
|
+
manifestTransforms?: ManifestTransform[];
|
41
50
|
}
|
42
51
|
/**
|
43
|
-
* Retrieves the precache manifest generated by SvelteKit.
|
44
|
-
*
|
52
|
+
* Retrieves the precache manifest generated by SvelteKit. A simple
|
53
|
+
* wrapper around SvelteKit's built-in service worker support. For more
|
54
|
+
* complex use cases, seek [the `@serwist/vite` recipe for SvelteKit](https://serwist.pages.dev/docs/vite/recipes/svelte-kit).
|
45
55
|
*
|
46
56
|
* @param options
|
47
57
|
* @returns
|
48
58
|
*/
|
49
|
-
export declare const getPrecacheManifest: ({ precacheImmutable, precacheStatic, precachePrerendered, staticRevisions, }?: GetPrecacheManifestOptions) => PrecacheEntry[];
|
59
|
+
export declare const getPrecacheManifest: ({ precacheImmutable, precacheStatic, precachePrerendered, staticRevisions, manifestTransforms, }?: GetPrecacheManifestOptions) => PrecacheEntry[] | undefined;
|
50
60
|
export declare const defaultIgnoreUrlParameters: RegExp[];
|
61
|
+
/**
|
62
|
+
* The default, recommended list of caching strategies for applications
|
63
|
+
* built with SvelteKit.
|
64
|
+
*
|
65
|
+
* @see https://serwist.pages.dev/docs/svelte/worker-exports#default-cache
|
66
|
+
*/
|
51
67
|
export declare const defaultCache: RuntimeCaching[];
|
52
68
|
//# sourceMappingURL=index.worker.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI7D,OAAO,EACL,IAAI,IAAI,QAAQ,EAChB,KAAK,IAAI,eAAe,EACxB,KAAK,IAAI,YAAY,EACrB,WAAW,IAAI,iBAAiB,EAChC,OAAO,IAAI,oBAAoB,EAChC,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC;AAE5F,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK;IAC7D,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACjC,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,sGAM7B,0BAA0B,KAAQ,aAAa,EAAE,GAAG,SA2CtD,CAAC;AAEF,eAAO,MAAM,0BAA0B,UAAgC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,cAAc,EA8GpC,CAAC"}
|
package/dist/index.worker.js
CHANGED
@@ -1,17 +1,14 @@
|
|
1
|
-
import { ExpirationPlugin } from '
|
2
|
-
import {
|
1
|
+
import { CacheFirst, ExpirationPlugin, StaleWhileRevalidate, NetworkFirst } from 'serwist';
|
2
|
+
import { logger } from 'serwist/internal';
|
3
3
|
import { build, files, prerendered, version } from '$service-worker';
|
4
|
-
export { build as immutableAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion, files as staticAssets } from '$service-worker';
|
4
|
+
export { base as basePath, build as immutableAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion, files as staticAssets } from '$service-worker';
|
5
5
|
|
6
|
-
const getPrecacheManifest = ({ precacheImmutable = true, precacheStatic = true, precachePrerendered = true, staticRevisions } = {})=>{
|
7
|
-
const staticMapper = (url)=>{
|
8
|
-
const revision = staticRevisions !== undefined && url in staticRevisions ? staticRevisions[url] : version;
|
9
|
-
return {
|
6
|
+
const getPrecacheManifest = ({ precacheImmutable = true, precacheStatic = true, precachePrerendered = true, staticRevisions, manifestTransforms } = {})=>{
|
7
|
+
const staticMapper = (url)=>({
|
10
8
|
url,
|
11
|
-
revision
|
12
|
-
};
|
13
|
-
|
14
|
-
return [
|
9
|
+
revision: typeof staticRevisions === "string" ? staticRevisions : typeof staticRevisions === "object" ? url in staticRevisions ? staticRevisions[url] : version : version
|
10
|
+
});
|
11
|
+
let precacheManifest = [
|
15
12
|
...precacheImmutable ? build.map((url)=>({
|
16
13
|
url,
|
17
14
|
revision: null
|
@@ -22,11 +19,34 @@ const getPrecacheManifest = ({ precacheImmutable = true, precacheStatic = true,
|
|
22
19
|
revision: version
|
23
20
|
})) : []
|
24
21
|
];
|
22
|
+
if (manifestTransforms) {
|
23
|
+
const allWarnings = [];
|
24
|
+
for (const transform of manifestTransforms){
|
25
|
+
const result = transform(precacheManifest);
|
26
|
+
if (!("manifest" in result)) {
|
27
|
+
if (process.env.NODE_ENV !== "production") {
|
28
|
+
logger.error("The return value from a manifestTransform should be an object with 'manifest' and optionally 'warnings' properties.");
|
29
|
+
}
|
30
|
+
return undefined;
|
31
|
+
}
|
32
|
+
precacheManifest = result.manifest;
|
33
|
+
allWarnings.push(...result.warnings || []);
|
34
|
+
}
|
35
|
+
if (process.env.NODE_ENV !== "production" && allWarnings.length > 0) {
|
36
|
+
logger.warn("Received warnings while transforming the precache manifest.");
|
37
|
+
logger.groupCollapsed("View details here.");
|
38
|
+
for (const warning of allWarnings){
|
39
|
+
logger.warn(warning);
|
40
|
+
}
|
41
|
+
logger.groupEnd();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return precacheManifest;
|
25
45
|
};
|
26
46
|
const defaultIgnoreUrlParameters = [
|
27
47
|
/^x-sveltekit-invalidated$/
|
28
48
|
];
|
29
|
-
const defaultCache = [
|
49
|
+
const defaultCache = import.meta.env.DEV ? [] : [
|
30
50
|
{
|
31
51
|
matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
|
32
52
|
handler: new CacheFirst({
|
@@ -34,7 +54,8 @@ const defaultCache = [
|
|
34
54
|
plugins: [
|
35
55
|
new ExpirationPlugin({
|
36
56
|
maxEntries: 4,
|
37
|
-
maxAgeSeconds: 365 * 24 * 60 * 60
|
57
|
+
maxAgeSeconds: 365 * 24 * 60 * 60,
|
58
|
+
maxAgeFrom: "last-used"
|
38
59
|
})
|
39
60
|
]
|
40
61
|
})
|
@@ -46,7 +67,8 @@ const defaultCache = [
|
|
46
67
|
plugins: [
|
47
68
|
new ExpirationPlugin({
|
48
69
|
maxEntries: 4,
|
49
|
-
maxAgeSeconds: 7 * 24 * 60 * 60
|
70
|
+
maxAgeSeconds: 7 * 24 * 60 * 60,
|
71
|
+
maxAgeFrom: "last-used"
|
50
72
|
})
|
51
73
|
]
|
52
74
|
})
|
@@ -58,7 +80,8 @@ const defaultCache = [
|
|
58
80
|
plugins: [
|
59
81
|
new ExpirationPlugin({
|
60
82
|
maxEntries: 64,
|
61
|
-
maxAgeSeconds: 24 * 60 * 60
|
83
|
+
maxAgeSeconds: 24 * 60 * 60,
|
84
|
+
maxAgeFrom: "last-used"
|
62
85
|
})
|
63
86
|
]
|
64
87
|
})
|
@@ -70,7 +93,8 @@ const defaultCache = [
|
|
70
93
|
plugins: [
|
71
94
|
new ExpirationPlugin({
|
72
95
|
maxEntries: 32,
|
73
|
-
maxAgeSeconds: 24 * 60 * 60
|
96
|
+
maxAgeSeconds: 24 * 60 * 60,
|
97
|
+
maxAgeFrom: "last-used"
|
74
98
|
})
|
75
99
|
]
|
76
100
|
})
|
@@ -82,7 +106,8 @@ const defaultCache = [
|
|
82
106
|
plugins: [
|
83
107
|
new ExpirationPlugin({
|
84
108
|
maxEntries: 32,
|
85
|
-
maxAgeSeconds: 24 * 60 * 60
|
109
|
+
maxAgeSeconds: 24 * 60 * 60,
|
110
|
+
maxAgeFrom: "last-used"
|
86
111
|
})
|
87
112
|
]
|
88
113
|
})
|
@@ -94,7 +119,8 @@ const defaultCache = [
|
|
94
119
|
plugins: [
|
95
120
|
new ExpirationPlugin({
|
96
121
|
maxEntries: 32,
|
97
|
-
maxAgeSeconds: 24 * 60 * 60
|
122
|
+
maxAgeSeconds: 24 * 60 * 60,
|
123
|
+
maxAgeFrom: "last-used"
|
98
124
|
})
|
99
125
|
]
|
100
126
|
})
|
@@ -107,7 +133,8 @@ const defaultCache = [
|
|
107
133
|
plugins: [
|
108
134
|
new ExpirationPlugin({
|
109
135
|
maxEntries: 16,
|
110
|
-
maxAgeSeconds: 24 * 60 * 60
|
136
|
+
maxAgeSeconds: 24 * 60 * 60,
|
137
|
+
maxAgeFrom: "last-used"
|
111
138
|
})
|
112
139
|
],
|
113
140
|
networkTimeoutSeconds: 10
|
@@ -120,7 +147,8 @@ const defaultCache = [
|
|
120
147
|
plugins: [
|
121
148
|
new ExpirationPlugin({
|
122
149
|
maxEntries: 32,
|
123
|
-
maxAgeSeconds: 24 * 60 * 60
|
150
|
+
maxAgeSeconds: 24 * 60 * 60,
|
151
|
+
maxAgeFrom: "last-used"
|
124
152
|
})
|
125
153
|
],
|
126
154
|
networkTimeoutSeconds: 10
|
package/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "@serwist/svelte",
|
3
|
-
"version": "9.0.0
|
3
|
+
"version": "9.0.0",
|
4
4
|
"type": "module",
|
5
|
-
"description": "A module that
|
5
|
+
"description": "A module that complements SvelteKit's built-in service worker support.",
|
6
6
|
"files": [
|
7
7
|
"src",
|
8
8
|
"dist"
|
@@ -22,7 +22,7 @@
|
|
22
22
|
],
|
23
23
|
"author": "Serwist's Team",
|
24
24
|
"license": "MIT",
|
25
|
-
"repository": "serwist/serwist",
|
25
|
+
"repository": "https://github.com/serwist/serwist",
|
26
26
|
"bugs": "https://github.com/serwist/serwist/issues",
|
27
27
|
"homepage": "https://serwist.pages.dev",
|
28
28
|
"typesVersions": {
|
@@ -40,25 +40,18 @@
|
|
40
40
|
"./package.json": "./package.json"
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
|
-
"
|
44
|
-
"@serwist/strategies": "9.0.0-preview.9"
|
43
|
+
"serwist": "9.0.0"
|
45
44
|
},
|
46
45
|
"devDependencies": {
|
47
|
-
"@sveltejs/kit": "2.5.
|
48
|
-
"rollup": "4.
|
49
|
-
"@serwist/
|
50
|
-
"@serwist/precaching": "9.0.0-preview.9",
|
51
|
-
"@serwist/sw": "9.0.0-preview.9"
|
46
|
+
"@sveltejs/kit": "2.5.6",
|
47
|
+
"rollup": "4.14.3",
|
48
|
+
"@serwist/configs": "9.0.0"
|
52
49
|
},
|
53
50
|
"peerDependencies": {
|
54
51
|
"@sveltejs/kit": ">=2.0.0",
|
55
|
-
"typescript": ">=5.0.0"
|
56
|
-
"@serwist/sw": "9.0.0-preview.9"
|
52
|
+
"typescript": ">=5.0.0"
|
57
53
|
},
|
58
54
|
"peerDependenciesMeta": {
|
59
|
-
"@serwist/sw": {
|
60
|
-
"optional": true
|
61
|
-
},
|
62
55
|
"typescript": {
|
63
56
|
"optional": true
|
64
57
|
}
|
package/src/index.worker.ts
CHANGED
@@ -1,13 +1,23 @@
|
|
1
|
-
import {
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import type { RuntimeCaching } from "@serwist/sw";
|
1
|
+
import type { PrecacheEntry, RuntimeCaching } from "serwist";
|
2
|
+
import { CacheFirst, ExpirationPlugin, NetworkFirst, StaleWhileRevalidate } from "serwist";
|
3
|
+
import { logger } from "serwist/internal";
|
5
4
|
|
6
|
-
import {
|
5
|
+
import {
|
6
|
+
base as basePath,
|
7
|
+
build as immutableAssets,
|
8
|
+
files as staticAssets,
|
9
|
+
prerendered as prerenderedRoutes,
|
10
|
+
version as serviceWorkerVersion,
|
11
|
+
} from "$service-worker";
|
7
12
|
|
8
|
-
export { immutableAssets, staticAssets, prerenderedRoutes, serviceWorkerVersion };
|
13
|
+
export { basePath, immutableAssets, staticAssets, prerenderedRoutes, serviceWorkerVersion };
|
9
14
|
|
10
|
-
export type StaticRevisions = { [url: string]: string | null };
|
15
|
+
export type StaticRevisions = string | { [url: string]: string | null };
|
16
|
+
|
17
|
+
export type ManifestTransform = (manifest: PrecacheEntry[]) => {
|
18
|
+
manifest: PrecacheEntry[];
|
19
|
+
warnings?: string[] | undefined;
|
20
|
+
};
|
11
21
|
|
12
22
|
export interface GetPrecacheManifestOptions {
|
13
23
|
/**
|
@@ -31,21 +41,28 @@ export interface GetPrecacheManifestOptions {
|
|
31
41
|
*/
|
32
42
|
precachePrerendered?: boolean;
|
33
43
|
/**
|
34
|
-
*
|
35
|
-
*
|
44
|
+
* A string revision used for all static assets or an object that maps
|
45
|
+
* URLs of static assets to custom revisions.
|
46
|
+
* If an URL doesn't exist in the object, `serviceWorkerVersion`
|
36
47
|
* will be used instead.
|
37
48
|
*
|
38
49
|
* This helps prevent such assets, which are unlikely to change, from
|
39
|
-
* being invalidated every time the service worker is
|
50
|
+
* being invalidated every time the service worker is rebuilt and updated.
|
40
51
|
*
|
41
|
-
* Note: you should prefix these URLs with
|
52
|
+
* Note: you should prefix these URLs with `basePath`.
|
42
53
|
*/
|
43
54
|
staticRevisions?: StaticRevisions;
|
55
|
+
/**
|
56
|
+
* One or more functions which will be applied sequentially against the
|
57
|
+
* generated manifest.
|
58
|
+
*/
|
59
|
+
manifestTransforms?: ManifestTransform[];
|
44
60
|
}
|
45
61
|
|
46
62
|
/**
|
47
|
-
* Retrieves the precache manifest generated by SvelteKit.
|
48
|
-
*
|
63
|
+
* Retrieves the precache manifest generated by SvelteKit. A simple
|
64
|
+
* wrapper around SvelteKit's built-in service worker support. For more
|
65
|
+
* complex use cases, seek [the `@serwist/vite` recipe for SvelteKit](https://serwist.pages.dev/docs/vite/recipes/svelte-kit).
|
49
66
|
*
|
50
67
|
* @param options
|
51
68
|
* @returns
|
@@ -55,121 +72,168 @@ export const getPrecacheManifest = ({
|
|
55
72
|
precacheStatic = true,
|
56
73
|
precachePrerendered = true,
|
57
74
|
staticRevisions,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
75
|
+
manifestTransforms,
|
76
|
+
}: GetPrecacheManifestOptions = {}): PrecacheEntry[] | undefined => {
|
77
|
+
const staticMapper = (url: string): PrecacheEntry => ({
|
78
|
+
url,
|
79
|
+
revision:
|
80
|
+
typeof staticRevisions === "string"
|
81
|
+
? staticRevisions
|
82
|
+
: typeof staticRevisions === "object"
|
83
|
+
? url in staticRevisions
|
84
|
+
? staticRevisions[url]
|
85
|
+
: serviceWorkerVersion
|
86
|
+
: serviceWorkerVersion,
|
87
|
+
});
|
88
|
+
let precacheManifest: PrecacheEntry[] = [
|
64
89
|
// Immutable files generated by Vite.
|
65
|
-
...(precacheImmutable ? immutableAssets.map((url) =>
|
90
|
+
...(precacheImmutable ? immutableAssets.map((url) => <PrecacheEntry>{ url, revision: null }) : []),
|
66
91
|
// Files in the static directory.
|
67
92
|
...(precacheStatic ? staticAssets.map(staticMapper) : []),
|
68
93
|
// Prerendered routes.
|
69
|
-
...(precachePrerendered ? prerenderedRoutes.map((url) =>
|
94
|
+
...(precachePrerendered ? prerenderedRoutes.map((url) => <PrecacheEntry>{ url, revision: serviceWorkerVersion }) : []),
|
70
95
|
];
|
96
|
+
if (manifestTransforms) {
|
97
|
+
const allWarnings: string[] = [];
|
98
|
+
for (const transform of manifestTransforms) {
|
99
|
+
const result = transform(precacheManifest);
|
100
|
+
if (!("manifest" in result)) {
|
101
|
+
if (process.env.NODE_ENV !== "production") {
|
102
|
+
logger.error("The return value from a manifestTransform should be an object with 'manifest' and optionally 'warnings' properties.");
|
103
|
+
}
|
104
|
+
return undefined;
|
105
|
+
}
|
106
|
+
precacheManifest = result.manifest;
|
107
|
+
allWarnings.push(...(result.warnings || []));
|
108
|
+
}
|
109
|
+
if (process.env.NODE_ENV !== "production" && allWarnings.length > 0) {
|
110
|
+
logger.warn("Received warnings while transforming the precache manifest.");
|
111
|
+
logger.groupCollapsed("View details here.");
|
112
|
+
for (const warning of allWarnings) {
|
113
|
+
logger.warn(warning);
|
114
|
+
}
|
115
|
+
logger.groupEnd();
|
116
|
+
}
|
117
|
+
}
|
118
|
+
return precacheManifest;
|
71
119
|
};
|
72
120
|
|
73
121
|
export const defaultIgnoreUrlParameters = [/^x-sveltekit-invalidated$/];
|
74
122
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
123
|
+
/**
|
124
|
+
* The default, recommended list of caching strategies for applications
|
125
|
+
* built with SvelteKit.
|
126
|
+
*
|
127
|
+
* @see https://serwist.pages.dev/docs/svelte/worker-exports#default-cache
|
128
|
+
*/
|
129
|
+
export const defaultCache: RuntimeCaching[] = import.meta.env.DEV
|
130
|
+
? []
|
131
|
+
: [
|
132
|
+
{
|
133
|
+
matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
|
134
|
+
handler: new CacheFirst({
|
135
|
+
cacheName: "google-fonts",
|
136
|
+
plugins: [
|
137
|
+
new ExpirationPlugin({
|
138
|
+
maxEntries: 4,
|
139
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
|
140
|
+
maxAgeFrom: "last-used",
|
141
|
+
}),
|
142
|
+
],
|
84
143
|
}),
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
144
|
+
},
|
145
|
+
{
|
146
|
+
matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
147
|
+
handler: new StaleWhileRevalidate({
|
148
|
+
cacheName: "static-font-assets",
|
149
|
+
plugins: [
|
150
|
+
new ExpirationPlugin({
|
151
|
+
maxEntries: 4,
|
152
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
153
|
+
maxAgeFrom: "last-used",
|
154
|
+
}),
|
155
|
+
],
|
96
156
|
}),
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
157
|
+
},
|
158
|
+
{
|
159
|
+
matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
160
|
+
handler: new StaleWhileRevalidate({
|
161
|
+
cacheName: "static-image-assets",
|
162
|
+
plugins: [
|
163
|
+
new ExpirationPlugin({
|
164
|
+
maxEntries: 64,
|
165
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
166
|
+
maxAgeFrom: "last-used",
|
167
|
+
}),
|
168
|
+
],
|
108
169
|
}),
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
170
|
+
},
|
171
|
+
{
|
172
|
+
matcher: /\.(?:js)$/i,
|
173
|
+
handler: new StaleWhileRevalidate({
|
174
|
+
cacheName: "static-js-assets",
|
175
|
+
plugins: [
|
176
|
+
new ExpirationPlugin({
|
177
|
+
maxEntries: 32,
|
178
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
179
|
+
maxAgeFrom: "last-used",
|
180
|
+
}),
|
181
|
+
],
|
120
182
|
}),
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
183
|
+
},
|
184
|
+
{
|
185
|
+
matcher: /\.(?:css|less)$/i,
|
186
|
+
handler: new StaleWhileRevalidate({
|
187
|
+
cacheName: "static-style-assets",
|
188
|
+
plugins: [
|
189
|
+
new ExpirationPlugin({
|
190
|
+
maxEntries: 32,
|
191
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
192
|
+
maxAgeFrom: "last-used",
|
193
|
+
}),
|
194
|
+
],
|
132
195
|
}),
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
196
|
+
},
|
197
|
+
{
|
198
|
+
matcher: /\.(?:json|xml|csv)$/i,
|
199
|
+
handler: new NetworkFirst({
|
200
|
+
cacheName: "static-data-assets",
|
201
|
+
plugins: [
|
202
|
+
new ExpirationPlugin({
|
203
|
+
maxEntries: 32,
|
204
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
205
|
+
maxAgeFrom: "last-used",
|
206
|
+
}),
|
207
|
+
],
|
144
208
|
}),
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
209
|
+
},
|
210
|
+
{
|
211
|
+
matcher: /\/api\/.*$/i,
|
212
|
+
method: "GET",
|
213
|
+
handler: new NetworkFirst({
|
214
|
+
cacheName: "apis",
|
215
|
+
plugins: [
|
216
|
+
new ExpirationPlugin({
|
217
|
+
maxEntries: 16,
|
218
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
219
|
+
maxAgeFrom: "last-used",
|
220
|
+
}),
|
221
|
+
],
|
222
|
+
networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
|
157
223
|
}),
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
224
|
+
},
|
225
|
+
{
|
226
|
+
matcher: /.*/i,
|
227
|
+
handler: new NetworkFirst({
|
228
|
+
cacheName: "others",
|
229
|
+
plugins: [
|
230
|
+
new ExpirationPlugin({
|
231
|
+
maxEntries: 32,
|
232
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
233
|
+
maxAgeFrom: "last-used",
|
234
|
+
}),
|
235
|
+
],
|
236
|
+
networkTimeoutSeconds: 10,
|
170
237
|
}),
|
171
|
-
|
172
|
-
|
173
|
-
}),
|
174
|
-
},
|
175
|
-
];
|
238
|
+
},
|
239
|
+
];
|