@serwist/next 9.5.7 → 9.5.8
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/chunks/schema-BhRhcBIb.js +22 -0
- package/dist/chunks/schema-BhRhcBIb.js.map +1 -0
- package/dist/index.config.d.mts +50 -0
- package/dist/index.config.d.mts.map +1 -0
- package/dist/index.config.mjs +89 -0
- package/dist/index.config.mjs.map +1 -0
- package/dist/index.d.mts +111 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +242 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.react.d.mts +41 -0
- package/dist/index.react.d.mts.map +1 -0
- package/dist/index.react.mjs +73 -0
- package/dist/index.react.mjs.map +1 -0
- package/dist/index.schema.d.mts +94 -0
- package/dist/index.schema.d.mts.map +1 -0
- package/dist/index.schema.mjs +2 -0
- package/dist/index.worker.d.mts +18 -0
- package/dist/index.worker.d.mts.map +1 -0
- package/dist/index.worker.mjs +227 -0
- package/dist/index.worker.mjs.map +1 -0
- package/dist/sw-entry-worker.d.mts +11 -0
- package/dist/sw-entry-worker.d.mts.map +1 -0
- package/dist/sw-entry-worker.mjs +25 -0
- package/dist/sw-entry-worker.mjs.map +1 -0
- package/dist/sw-entry.d.mts +9 -0
- package/dist/sw-entry.d.mts.map +1 -0
- package/dist/sw-entry.mjs +37 -0
- package/dist/sw-entry.mjs.map +1 -0
- package/package.json +37 -38
- package/src/index.react.tsx +2 -2
- package/src/index.ts +2 -2
- package/src/lib/config/utils.ts +3 -2
- package/dist/chunks/schema.js +0 -24
- package/dist/index.config.d.ts +0 -36
- package/dist/index.config.d.ts.map +0 -1
- package/dist/index.config.js +0 -118
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -285
- package/dist/index.react.d.ts +0 -25
- package/dist/index.react.d.ts.map +0 -1
- package/dist/index.react.js +0 -88
- package/dist/index.schema.d.ts +0 -3
- package/dist/index.schema.d.ts.map +0 -1
- package/dist/index.schema.js +0 -4
- package/dist/index.worker.d.ts +0 -14
- package/dist/index.worker.d.ts.map +0 -1
- package/dist/index.worker.js +0 -261
- package/dist/internal-types.d.ts +0 -15
- package/dist/internal-types.d.ts.map +0 -1
- package/dist/lib/config/constants.d.ts +0 -2
- package/dist/lib/config/constants.d.ts.map +0 -1
- package/dist/lib/config/types.d.ts +0 -11
- package/dist/lib/config/types.d.ts.map +0 -1
- package/dist/lib/config/utils.d.ts +0 -3
- package/dist/lib/config/utils.d.ts.map +0 -1
- package/dist/lib/context.d.ts +0 -7
- package/dist/lib/context.d.ts.map +0 -1
- package/dist/lib/find-first-truthy.d.ts +0 -8
- package/dist/lib/find-first-truthy.d.ts.map +0 -1
- package/dist/lib/get-content-hash.d.ts +0 -3
- package/dist/lib/get-content-hash.d.ts.map +0 -1
- package/dist/lib/get-file-hash.d.ts +0 -3
- package/dist/lib/get-file-hash.d.ts.map +0 -1
- package/dist/lib/get-package-version.d.ts +0 -7
- package/dist/lib/get-package-version.d.ts.map +0 -1
- package/dist/lib/index.d.ts +0 -7
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/load-tsconfig.d.ts +0 -3
- package/dist/lib/load-tsconfig.d.ts.map +0 -1
- package/dist/lib/logger.d.ts +0 -7
- package/dist/lib/logger.d.ts.map +0 -1
- package/dist/lib/schema.d.ts +0 -90
- package/dist/lib/schema.d.ts.map +0 -1
- package/dist/lib/types.d.ts +0 -95
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/validator.d.ts +0 -3
- package/dist/lib/validator.d.ts.map +0 -1
- package/dist/sw-entry-worker.d.ts +0 -8
- package/dist/sw-entry-worker.d.ts.map +0 -1
- package/dist/sw-entry-worker.js +0 -33
- package/dist/sw-entry.d.ts +0 -7
- package/dist/sw-entry.d.ts.map +0 -1
- package/dist/sw-entry.js +0 -43
- package/dist/utils.d.ts +0 -4
- package/dist/utils.d.ts.map +0 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Serwist } from "@serwist/window";
|
|
2
|
+
import { isCurrentPageOutOfScope } from "@serwist/window/internal";
|
|
3
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
//#region src/lib/context.ts
|
|
5
|
+
const SerwistContext = createContext(null);
|
|
6
|
+
const useSerwist = () => {
|
|
7
|
+
const context = useContext(SerwistContext);
|
|
8
|
+
if (!context) throw new Error("[useSerwist]: 'SerwistContext' is not available.");
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/index.react.tsx
|
|
13
|
+
/**
|
|
14
|
+
* `@serwist/window` provider for Next.js apps.
|
|
15
|
+
* @param options
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
function SerwistProvider({ swUrl, disable = false, register = true, cacheOnNavigation = true, reloadOnOnline = true, options, children }) {
|
|
19
|
+
const [serwist] = useState(() => {
|
|
20
|
+
if (typeof window === "undefined") return null;
|
|
21
|
+
if (disable) return null;
|
|
22
|
+
const scope = options?.scope || "/";
|
|
23
|
+
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
24
|
+
window.serwist = new Serwist(swUrl, {
|
|
25
|
+
...options,
|
|
26
|
+
scope,
|
|
27
|
+
type: options?.type || "module"
|
|
28
|
+
});
|
|
29
|
+
if (register && !isCurrentPageOutOfScope(scope)) window.serwist.register();
|
|
30
|
+
}
|
|
31
|
+
return window.serwist ?? null;
|
|
32
|
+
});
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const cacheUrls = async (url) => {
|
|
35
|
+
if (!window.navigator.onLine || !url) return;
|
|
36
|
+
serwist?.messageSW({
|
|
37
|
+
type: "CACHE_URLS",
|
|
38
|
+
payload: { urlsToCache: [url] }
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const cacheCurrentPathname = () => cacheUrls(window.location.pathname);
|
|
42
|
+
const pushState = history.pushState;
|
|
43
|
+
const replaceState = history.replaceState;
|
|
44
|
+
if (cacheOnNavigation) {
|
|
45
|
+
history.pushState = (...args) => {
|
|
46
|
+
pushState.apply(history, args);
|
|
47
|
+
cacheUrls(args[2]);
|
|
48
|
+
};
|
|
49
|
+
history.replaceState = (...args) => {
|
|
50
|
+
replaceState.apply(history, args);
|
|
51
|
+
cacheUrls(args[2]);
|
|
52
|
+
};
|
|
53
|
+
window.addEventListener("online", cacheCurrentPathname);
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
history.pushState = pushState;
|
|
57
|
+
history.replaceState = replaceState;
|
|
58
|
+
window.removeEventListener("online", cacheCurrentPathname);
|
|
59
|
+
};
|
|
60
|
+
}, [serwist?.messageSW, cacheOnNavigation]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const reload = () => location.reload();
|
|
63
|
+
if (reloadOnOnline) window.addEventListener("online", reload);
|
|
64
|
+
return () => {
|
|
65
|
+
window.removeEventListener("online", reload);
|
|
66
|
+
};
|
|
67
|
+
}, [reloadOnOnline]);
|
|
68
|
+
return <SerwistContext.Provider value={{ serwist }}>{children}</SerwistContext.Provider>;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { SerwistProvider, useSerwist };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=index.react.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.react.mjs","names":[],"sources":["../src/lib/context.ts","../src/index.react.tsx"],"sourcesContent":["import type { Serwist } from \"@serwist/window\";\nimport { createContext, useContext } from \"react\";\n\nexport interface SerwistContextValues {\n serwist: Serwist | null;\n}\n\nexport const SerwistContext = createContext<SerwistContextValues>(null!);\n\nexport const useSerwist = () => {\n const context = useContext(SerwistContext);\n if (!context) {\n throw new Error(\"[useSerwist]: 'SerwistContext' is not available.\");\n }\n return context;\n};\n","import { Serwist } from \"@serwist/window\";\nimport { isCurrentPageOutOfScope } from \"@serwist/window/internal\";\nimport { type JSX, type ReactNode, useEffect, useState } from \"react\";\nimport { SerwistContext, useSerwist } from \"./lib/context.js\";\n\nexport interface SerwistProviderProps {\n swUrl: string;\n disable?: boolean;\n register?: boolean;\n cacheOnNavigation?: boolean;\n reloadOnOnline?: boolean;\n options?: RegistrationOptions;\n children?: ReactNode;\n}\n\ndeclare global {\n interface Window {\n serwist: Serwist;\n }\n}\n\n/**\n * `@serwist/window` provider for Next.js apps.\n * @param options\n * @returns\n */\nexport function SerwistProvider({\n swUrl,\n disable = false,\n register = true,\n cacheOnNavigation = true,\n reloadOnOnline = true,\n options,\n children,\n}: SerwistProviderProps): JSX.Element {\n const [serwist] = useState(() => {\n if (typeof window === \"undefined\") return null;\n if (disable) return null;\n const scope = options?.scope || \"/\";\n if (!(window.serwist && window.serwist instanceof Serwist) && \"serviceWorker\" in navigator) {\n window.serwist = new Serwist(swUrl, { ...options, scope, type: options?.type || \"module\" });\n if (register && !isCurrentPageOutOfScope(scope)) {\n void window.serwist.register();\n }\n }\n return window.serwist ?? null;\n });\n useEffect(() => {\n const cacheUrls = async (url?: string | URL | null | undefined) => {\n if (!window.navigator.onLine || !url) {\n return;\n }\n serwist?.messageSW({\n type: \"CACHE_URLS\",\n payload: { urlsToCache: [url] },\n });\n };\n const cacheCurrentPathname = () => cacheUrls(window.location.pathname);\n const pushState = history.pushState;\n const replaceState = history.replaceState;\n\n if (cacheOnNavigation) {\n history.pushState = (...args) => {\n pushState.apply(history, args);\n cacheUrls(args[2]);\n };\n history.replaceState = (...args) => {\n replaceState.apply(history, args);\n cacheUrls(args[2]);\n };\n window.addEventListener(\"online\", cacheCurrentPathname);\n }\n\n return () => {\n history.pushState = pushState;\n history.replaceState = replaceState;\n window.removeEventListener(\"online\", cacheCurrentPathname);\n };\n }, [serwist?.messageSW, cacheOnNavigation]);\n useEffect(() => {\n const reload = () => location.reload();\n if (reloadOnOnline) {\n window.addEventListener(\"online\", reload);\n }\n return () => {\n window.removeEventListener(\"online\", reload);\n };\n }, [reloadOnOnline]);\n return <SerwistContext.Provider value={{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,YAAY;AACpB,WAAQ,eAAe;AACvB,UAAO,oBAAoB,UAAU,qBAAqB;;IAE3D,CAAC,SAAS,WAAW,kBAAkB,CAAC;AAC3C,iBAAgB;EACd,MAAM,eAAe,SAAS,QAAQ;AACtC,MAAI,eACF,QAAO,iBAAiB,UAAU,OAAO;AAE3C,eAAa;AACX,UAAO,oBAAoB,UAAU,OAAO;;IAE7C,CAAC,eAAe,CAAC;AACpB,QAAO,CAAC,eAAe,SAAS,OAAO,EAAE,SAAS,GAAG,SAAS,EAAE,eAAe"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/schema.d.ts
|
|
4
|
+
declare const injectPartial: z.ZodObject<{
|
|
5
|
+
cacheOnNavigation: z.ZodDefault<z.ZodBoolean>;
|
|
6
|
+
disable: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
register: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
reloadOnOnline: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
10
|
+
swUrl: z.ZodDefault<z.ZodString>;
|
|
11
|
+
globPublicPatterns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
declare const injectManifestOptions: z.ZodObject<{
|
|
14
|
+
additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
15
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
16
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
url: z.ZodString;
|
|
18
|
+
}, z.core.$strict>]>>>;
|
|
19
|
+
dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
|
|
20
|
+
manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
21
|
+
size: z.ZodNumber;
|
|
22
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
23
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
url: z.ZodString;
|
|
25
|
+
}, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
26
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
27
|
+
size: z.ZodNumber;
|
|
28
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
29
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
url: z.ZodString;
|
|
31
|
+
}, z.core.$strip>>;
|
|
32
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
33
|
+
}, z.core.$strict>>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
34
|
+
size: z.ZodNumber;
|
|
35
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
36
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
37
|
+
url: z.ZodString;
|
|
38
|
+
}, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
39
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
40
|
+
size: z.ZodNumber;
|
|
41
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
42
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
url: z.ZodString;
|
|
44
|
+
}, z.core.$strip>>;
|
|
45
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
46
|
+
}, z.core.$strict>>>, z.ZodTransform<z.core.$InferOuterFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
47
|
+
size: z.ZodNumber;
|
|
48
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
49
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
+
url: z.ZodString;
|
|
51
|
+
}, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
52
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
53
|
+
size: z.ZodNumber;
|
|
54
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
55
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
56
|
+
url: z.ZodString;
|
|
57
|
+
}, z.core.$strip>>;
|
|
58
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
59
|
+
}, z.core.$strict>>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
60
|
+
size: z.ZodNumber;
|
|
61
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
62
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
url: z.ZodString;
|
|
64
|
+
}, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
65
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
66
|
+
size: z.ZodNumber;
|
|
67
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
68
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
|
+
url: z.ZodString;
|
|
70
|
+
}, z.core.$strip>>;
|
|
71
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
72
|
+
}, z.core.$strict>>>>>>;
|
|
73
|
+
maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
|
|
74
|
+
modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
75
|
+
chunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
76
|
+
exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
|
|
77
|
+
excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
78
|
+
include: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
|
|
79
|
+
injectionPoint: z.ZodDefault<z.ZodString>;
|
|
80
|
+
swSrc: z.ZodString;
|
|
81
|
+
swDest: z.ZodString;
|
|
82
|
+
compileSrc: z.ZodDefault<z.ZodBoolean>;
|
|
83
|
+
webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
84
|
+
cacheOnNavigation: z.ZodDefault<z.ZodBoolean>;
|
|
85
|
+
disable: z.ZodDefault<z.ZodBoolean>;
|
|
86
|
+
register: z.ZodDefault<z.ZodBoolean>;
|
|
87
|
+
reloadOnOnline: z.ZodDefault<z.ZodBoolean>;
|
|
88
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
89
|
+
swUrl: z.ZodDefault<z.ZodString>;
|
|
90
|
+
globPublicPatterns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
91
|
+
}, z.core.$strict>;
|
|
92
|
+
//#endregion
|
|
93
|
+
export { injectManifestOptions, injectPartial };
|
|
94
|
+
//# sourceMappingURL=index.schema.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.schema.d.mts","names":[],"sources":["../src/lib/schema.ts"],"mappings":";;;cAIa,aAAA,EAAa,CAAA,CAAA,SAAA;;;;;;;;;cAUb,qBAAA,EAAqB,CAAA,CAAA,SAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RuntimeCaching } from "serwist";
|
|
2
|
+
|
|
3
|
+
//#region src/index.worker.d.ts
|
|
4
|
+
declare const PAGES_CACHE_NAME: {
|
|
5
|
+
readonly rscPrefetch: "pages-rsc-prefetch";
|
|
6
|
+
readonly rsc: "pages-rsc";
|
|
7
|
+
readonly html: "pages";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The default, recommended list of caching strategies for applications
|
|
11
|
+
* built with Next.js.
|
|
12
|
+
*
|
|
13
|
+
* @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
|
|
14
|
+
*/
|
|
15
|
+
declare const defaultCache: RuntimeCaching[];
|
|
16
|
+
//#endregion
|
|
17
|
+
export { PAGES_CACHE_NAME, defaultCache };
|
|
18
|
+
//# sourceMappingURL=index.worker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.worker.d.mts","names":[],"sources":["../src/index.worker.ts"],"mappings":";;;cAGa,gBAAA;EAAA;;;;;;;;;;cAYA,YAAA,EAAc,cAAA"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { CacheFirst, ExpirationPlugin, NetworkFirst, NetworkOnly, RangeRequestsPlugin, StaleWhileRevalidate } from "serwist";
|
|
2
|
+
//#region src/index.worker.ts
|
|
3
|
+
const PAGES_CACHE_NAME = {
|
|
4
|
+
rscPrefetch: "pages-rsc-prefetch",
|
|
5
|
+
rsc: "pages-rsc",
|
|
6
|
+
html: "pages"
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The default, recommended list of caching strategies for applications
|
|
10
|
+
* built with Next.js.
|
|
11
|
+
*
|
|
12
|
+
* @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
|
|
13
|
+
*/
|
|
14
|
+
const defaultCache = process.env.NODE_ENV !== "production" ? [{
|
|
15
|
+
matcher: /.*/i,
|
|
16
|
+
handler: new NetworkOnly()
|
|
17
|
+
}] : [
|
|
18
|
+
{
|
|
19
|
+
matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
|
|
20
|
+
handler: new CacheFirst({
|
|
21
|
+
cacheName: "google-fonts-webfonts",
|
|
22
|
+
plugins: [new ExpirationPlugin({
|
|
23
|
+
maxEntries: 4,
|
|
24
|
+
maxAgeSeconds: 365 * 24 * 60 * 60,
|
|
25
|
+
maxAgeFrom: "last-used"
|
|
26
|
+
})]
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
matcher: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
|
|
31
|
+
handler: new StaleWhileRevalidate({
|
|
32
|
+
cacheName: "google-fonts-stylesheets",
|
|
33
|
+
plugins: [new ExpirationPlugin({
|
|
34
|
+
maxEntries: 4,
|
|
35
|
+
maxAgeSeconds: 10080 * 60,
|
|
36
|
+
maxAgeFrom: "last-used"
|
|
37
|
+
})]
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
|
42
|
+
handler: new StaleWhileRevalidate({
|
|
43
|
+
cacheName: "static-font-assets",
|
|
44
|
+
plugins: [new ExpirationPlugin({
|
|
45
|
+
maxEntries: 4,
|
|
46
|
+
maxAgeSeconds: 10080 * 60,
|
|
47
|
+
maxAgeFrom: "last-used"
|
|
48
|
+
})]
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
|
53
|
+
handler: new StaleWhileRevalidate({
|
|
54
|
+
cacheName: "static-image-assets",
|
|
55
|
+
plugins: [new ExpirationPlugin({
|
|
56
|
+
maxEntries: 64,
|
|
57
|
+
maxAgeSeconds: 720 * 60 * 60,
|
|
58
|
+
maxAgeFrom: "last-used"
|
|
59
|
+
})]
|
|
60
|
+
})
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
matcher: /\/_next\/static.+\.js$/i,
|
|
64
|
+
handler: new CacheFirst({
|
|
65
|
+
cacheName: "next-static-js-assets",
|
|
66
|
+
plugins: [new ExpirationPlugin({
|
|
67
|
+
maxEntries: 64,
|
|
68
|
+
maxAgeSeconds: 1440 * 60,
|
|
69
|
+
maxAgeFrom: "last-used"
|
|
70
|
+
})]
|
|
71
|
+
})
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
matcher: /\/_next\/image\?url=.+$/i,
|
|
75
|
+
handler: new StaleWhileRevalidate({
|
|
76
|
+
cacheName: "next-image",
|
|
77
|
+
plugins: [new ExpirationPlugin({
|
|
78
|
+
maxEntries: 64,
|
|
79
|
+
maxAgeSeconds: 1440 * 60,
|
|
80
|
+
maxAgeFrom: "last-used"
|
|
81
|
+
})]
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
matcher: /\.(?:mp3|wav|ogg)$/i,
|
|
86
|
+
handler: new CacheFirst({
|
|
87
|
+
cacheName: "static-audio-assets",
|
|
88
|
+
plugins: [new ExpirationPlugin({
|
|
89
|
+
maxEntries: 32,
|
|
90
|
+
maxAgeSeconds: 1440 * 60,
|
|
91
|
+
maxAgeFrom: "last-used"
|
|
92
|
+
}), new RangeRequestsPlugin()]
|
|
93
|
+
})
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
matcher: /\.(?:mp4|webm)$/i,
|
|
97
|
+
handler: new CacheFirst({
|
|
98
|
+
cacheName: "static-video-assets",
|
|
99
|
+
plugins: [new ExpirationPlugin({
|
|
100
|
+
maxEntries: 32,
|
|
101
|
+
maxAgeSeconds: 1440 * 60,
|
|
102
|
+
maxAgeFrom: "last-used"
|
|
103
|
+
}), new RangeRequestsPlugin()]
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
matcher: /\.(?:js)$/i,
|
|
108
|
+
handler: new StaleWhileRevalidate({
|
|
109
|
+
cacheName: "static-js-assets",
|
|
110
|
+
plugins: [new ExpirationPlugin({
|
|
111
|
+
maxEntries: 48,
|
|
112
|
+
maxAgeSeconds: 1440 * 60,
|
|
113
|
+
maxAgeFrom: "last-used"
|
|
114
|
+
})]
|
|
115
|
+
})
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
matcher: /\.(?:css|less)$/i,
|
|
119
|
+
handler: new StaleWhileRevalidate({
|
|
120
|
+
cacheName: "static-style-assets",
|
|
121
|
+
plugins: [new ExpirationPlugin({
|
|
122
|
+
maxEntries: 32,
|
|
123
|
+
maxAgeSeconds: 1440 * 60,
|
|
124
|
+
maxAgeFrom: "last-used"
|
|
125
|
+
})]
|
|
126
|
+
})
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
matcher: /\/_next\/data\/.+\/.+\.json$/i,
|
|
130
|
+
handler: new NetworkFirst({
|
|
131
|
+
cacheName: "next-data",
|
|
132
|
+
plugins: [new ExpirationPlugin({
|
|
133
|
+
maxEntries: 32,
|
|
134
|
+
maxAgeSeconds: 1440 * 60,
|
|
135
|
+
maxAgeFrom: "last-used"
|
|
136
|
+
})]
|
|
137
|
+
})
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
matcher: /\.(?:json|xml|csv)$/i,
|
|
141
|
+
handler: new NetworkFirst({
|
|
142
|
+
cacheName: "static-data-assets",
|
|
143
|
+
plugins: [new ExpirationPlugin({
|
|
144
|
+
maxEntries: 32,
|
|
145
|
+
maxAgeSeconds: 1440 * 60,
|
|
146
|
+
maxAgeFrom: "last-used"
|
|
147
|
+
})]
|
|
148
|
+
})
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
matcher: /\/api\/auth\/.*/,
|
|
152
|
+
handler: new NetworkOnly({ networkTimeoutSeconds: 10 })
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
matcher: ({ sameOrigin, url: { pathname } }) => sameOrigin && pathname.startsWith("/api/"),
|
|
156
|
+
method: "GET",
|
|
157
|
+
handler: new NetworkFirst({
|
|
158
|
+
cacheName: "apis",
|
|
159
|
+
plugins: [new ExpirationPlugin({
|
|
160
|
+
maxEntries: 16,
|
|
161
|
+
maxAgeSeconds: 1440 * 60,
|
|
162
|
+
maxAgeFrom: "last-used"
|
|
163
|
+
})],
|
|
164
|
+
networkTimeoutSeconds: 10
|
|
165
|
+
})
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
169
|
+
handler: new NetworkFirst({
|
|
170
|
+
cacheName: PAGES_CACHE_NAME.rscPrefetch,
|
|
171
|
+
plugins: [new ExpirationPlugin({
|
|
172
|
+
maxEntries: 32,
|
|
173
|
+
maxAgeSeconds: 1440 * 60
|
|
174
|
+
})]
|
|
175
|
+
})
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
179
|
+
handler: new NetworkFirst({
|
|
180
|
+
cacheName: PAGES_CACHE_NAME.rsc,
|
|
181
|
+
plugins: [new ExpirationPlugin({
|
|
182
|
+
maxEntries: 32,
|
|
183
|
+
maxAgeSeconds: 1440 * 60
|
|
184
|
+
})]
|
|
185
|
+
})
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
|
|
189
|
+
handler: new NetworkFirst({
|
|
190
|
+
cacheName: PAGES_CACHE_NAME.html,
|
|
191
|
+
plugins: [new ExpirationPlugin({
|
|
192
|
+
maxEntries: 32,
|
|
193
|
+
maxAgeSeconds: 1440 * 60
|
|
194
|
+
})]
|
|
195
|
+
})
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith("/api/"),
|
|
199
|
+
handler: new NetworkFirst({
|
|
200
|
+
cacheName: "others",
|
|
201
|
+
plugins: [new ExpirationPlugin({
|
|
202
|
+
maxEntries: 32,
|
|
203
|
+
maxAgeSeconds: 1440 * 60
|
|
204
|
+
})]
|
|
205
|
+
})
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
matcher: ({ sameOrigin }) => !sameOrigin,
|
|
209
|
+
handler: new NetworkFirst({
|
|
210
|
+
cacheName: "cross-origin",
|
|
211
|
+
plugins: [new ExpirationPlugin({
|
|
212
|
+
maxEntries: 32,
|
|
213
|
+
maxAgeSeconds: 3600
|
|
214
|
+
})],
|
|
215
|
+
networkTimeoutSeconds: 10
|
|
216
|
+
})
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
matcher: /.*/i,
|
|
220
|
+
method: "GET",
|
|
221
|
+
handler: new NetworkOnly()
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
//#endregion
|
|
225
|
+
export { PAGES_CACHE_NAME, defaultCache };
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=index.worker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.worker.mjs","names":[],"sources":["../src/index.worker.ts"],"sourcesContent":["import type { RuntimeCaching } from \"serwist\";\nimport { CacheFirst, ExpirationPlugin, NetworkFirst, NetworkOnly, RangeRequestsPlugin, StaleWhileRevalidate } from \"serwist\";\n\nexport const PAGES_CACHE_NAME = {\n rscPrefetch: \"pages-rsc-prefetch\",\n rsc: \"pages-rsc\",\n html: \"pages\",\n} as const;\n\n/**\n * The default, recommended list of caching strategies for applications\n * built with Next.js.\n *\n * @see https://serwist.pages.dev/docs/next/worker-exports#default-cache\n */\nexport const defaultCache: RuntimeCaching[] =\n process.env.NODE_ENV !== \"production\"\n ? [\n {\n matcher: /.*/i,\n handler: new NetworkOnly(),\n },\n ]\n : [\n {\n matcher: /^https:\\/\\/fonts\\.(?:gstatic)\\.com\\/.*/i,\n handler: new CacheFirst({\n cacheName: \"google-fonts-webfonts\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 4,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /^https:\\/\\/fonts\\.(?:googleapis)\\.com\\/.*/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"google-fonts-stylesheets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 4,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-font-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 4,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-image-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 64,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\/_next\\/static.+\\.js$/i,\n handler: new CacheFirst({\n cacheName: \"next-static-js-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 64,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\/_next\\/image\\?url=.+$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"next-image\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 64,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:mp3|wav|ogg)$/i,\n handler: new CacheFirst({\n cacheName: \"static-audio-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n new RangeRequestsPlugin(),\n ],\n }),\n },\n {\n matcher: /\\.(?:mp4|webm)$/i,\n handler: new CacheFirst({\n cacheName: \"static-video-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n new RangeRequestsPlugin(),\n ],\n }),\n },\n {\n matcher: /\\.(?:js)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-js-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 48,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:css|less)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-style-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\/_next\\/data\\/.+\\/.+\\.json$/i,\n handler: new NetworkFirst({\n cacheName: \"next-data\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:json|xml|csv)$/i,\n handler: new NetworkFirst({\n cacheName: \"static-data-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n // Exclude /api/auth/* to fix auth callback\n // https://github.com/serwist/serwist/discussions/28\n matcher: /\\/api\\/auth\\/.*/,\n handler: new NetworkOnly({\n networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds\n }),\n },\n {\n matcher: ({ sameOrigin, url: { pathname } }) => sameOrigin && pathname.startsWith(\"/api/\"),\n method: \"GET\",\n handler: new NetworkFirst({\n cacheName: \"apis\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 16,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds\n }),\n },\n {\n matcher: ({ request, url: { pathname }, sameOrigin }) =>\n request.headers.get(\"RSC\") === \"1\" && request.headers.get(\"Next-Router-Prefetch\") === \"1\" && sameOrigin && !pathname.startsWith(\"/api/\"),\n handler: new NetworkFirst({\n cacheName: PAGES_CACHE_NAME.rscPrefetch,\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n }),\n ],\n }),\n },\n {\n matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get(\"RSC\") === \"1\" && sameOrigin && !pathname.startsWith(\"/api/\"),\n handler: new NetworkFirst({\n cacheName: PAGES_CACHE_NAME.rsc,\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n }),\n ],\n }),\n },\n {\n matcher: ({ request, url: { pathname }, sameOrigin }) =>\n request.headers.get(\"Content-Type\")?.includes(\"text/html\") && sameOrigin && !pathname.startsWith(\"/api/\"),\n handler: new NetworkFirst({\n cacheName: PAGES_CACHE_NAME.html,\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n }),\n ],\n }),\n },\n {\n matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith(\"/api/\"),\n handler: new NetworkFirst({\n cacheName: \"others\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n }),\n ],\n }),\n },\n {\n matcher: ({ sameOrigin }) => !sameOrigin,\n handler: new NetworkFirst({\n cacheName: \"cross-origin\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 60 * 60, // 1 hour\n }),\n ],\n networkTimeoutSeconds: 10,\n }),\n },\n {\n matcher: /.*/i,\n method: \"GET\",\n handler: new NetworkOnly(),\n },\n ];\n"],"mappings":";;AAGA,MAAa,mBAAmB;CAC9B,aAAa;CACb,KAAK;CACL,MAAM;CACP;;;;;;;AAQD,MAAa,eACX,QAAQ,IAAI,aAAa,eACrB,CACE;CACE,SAAS;CACT,SAAS,IAAI,aAAa;CAC3B,CACF,GACD;CACE;EACE,SAAS;EACT,SAAS,IAAI,WAAW;GACtB,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,MAAM,KAAK,KAAK;IAC/B,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,qBAAqB;GAChC,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,QAAc;IAC7B,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,qBAAqB;GAChC,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,QAAc;IAC7B,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,qBAAqB;GAChC,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,MAAU,KAAK;IAC9B,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,WAAW;GACtB,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WAAW,QAAQ;EAC3F,SAAS,IAAI,aAAa;GACxB,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,OAAU;IAC1B,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,UAAU,EAAE,iBAAiB,CAAC;EAC9B,SAAS,IAAI,aAAa;GACxB,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe;IAChB,CAAC,CACH;GACD,uBAAuB;GACxB,CAAC;EACH;CACD;EACE,SAAS;EACT,QAAQ;EACR,SAAS,IAAI,aAAa;EAC3B;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/sw-entry-worker.d.ts
|
|
2
|
+
type MessageType = {
|
|
3
|
+
type: "__FRONTEND_NAV_CACHE__";
|
|
4
|
+
url: URL | string;
|
|
5
|
+
} | {
|
|
6
|
+
type: "__START_URL_CACHE__";
|
|
7
|
+
url: URL | string;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { MessageType };
|
|
11
|
+
//# sourceMappingURL=sw-entry-worker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-entry-worker.d.mts","names":[],"sources":["../src/sw-entry-worker.ts"],"mappings":";KAEY,WAAA;EAEN,IAAA;EACA,GAAA,EAAK,GAAA;AAAA;EAGL,IAAA;EACA,GAAA,EAAK,GAAA;AAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/sw-entry-worker.ts
|
|
2
|
+
self.onmessage = async (ev) => {
|
|
3
|
+
switch (ev.data.type) {
|
|
4
|
+
case "__START_URL_CACHE__": {
|
|
5
|
+
const url = ev.data.url;
|
|
6
|
+
const response = await fetch(url);
|
|
7
|
+
if (!response.redirected) return (await caches.open("start-url")).put(url, response);
|
|
8
|
+
return Promise.resolve();
|
|
9
|
+
}
|
|
10
|
+
case "__FRONTEND_NAV_CACHE__": {
|
|
11
|
+
const url = ev.data.url;
|
|
12
|
+
const pagesCache = await caches.open("pages");
|
|
13
|
+
if (!!await pagesCache.match(url, { ignoreSearch: true })) return;
|
|
14
|
+
const page = await fetch(url);
|
|
15
|
+
if (!page.ok) return;
|
|
16
|
+
pagesCache.put(url, page.clone());
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
}
|
|
19
|
+
default: return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export {};
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=sw-entry-worker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-entry-worker.mjs","names":[],"sources":["../src/sw-entry-worker.ts"],"sourcesContent":["declare const self: WorkerGlobalScope & typeof globalThis;\n\nexport type MessageType =\n | {\n type: \"__FRONTEND_NAV_CACHE__\";\n url: URL | string;\n }\n | {\n type: \"__START_URL_CACHE__\";\n url: URL | string;\n };\n\nself.onmessage = async (ev: MessageEvent<MessageType>) => {\n switch (ev.data.type) {\n case \"__START_URL_CACHE__\": {\n const url = ev.data.url;\n const response = await fetch(url);\n if (!response.redirected) {\n const startUrlCache = await caches.open(\"start-url\");\n return startUrlCache.put(url, response);\n }\n return Promise.resolve();\n }\n case \"__FRONTEND_NAV_CACHE__\": {\n const url = ev.data.url;\n const pagesCache = await caches.open(\"pages\");\n\n const isPageCached = !!(await pagesCache.match(url, {\n ignoreSearch: true,\n }));\n if (isPageCached) {\n return;\n }\n\n const page = await fetch(url);\n if (!page.ok) {\n return;\n }\n pagesCache.put(url, page.clone());\n\n return Promise.resolve();\n }\n default:\n return Promise.resolve();\n }\n};\n"],"mappings":";AAYA,KAAK,YAAY,OAAO,OAAkC;AACxD,SAAQ,GAAG,KAAK,MAAhB;EACE,KAAK,uBAAuB;GAC1B,MAAM,MAAM,GAAG,KAAK;GACpB,MAAM,WAAW,MAAM,MAAM,IAAI;AACjC,OAAI,CAAC,SAAS,WAEZ,SAAO,MADqB,OAAO,KAAK,YAAY,EAC/B,IAAI,KAAK,SAAS;AAEzC,UAAO,QAAQ,SAAS;;EAE1B,KAAK,0BAA0B;GAC7B,MAAM,MAAM,GAAG,KAAK;GACpB,MAAM,aAAa,MAAM,OAAO,KAAK,QAAQ;AAK7C,OAAI,CAHkB,CAAE,MAAM,WAAW,MAAM,KAAK,EAClD,cAAc,MACf,CAAC,CAEA;GAGF,MAAM,OAAO,MAAM,MAAM,IAAI;AAC7B,OAAI,CAAC,KAAK,GACR;AAEF,cAAW,IAAI,KAAK,KAAK,OAAO,CAAC;AAEjC,UAAO,QAAQ,SAAS;;EAE1B,QACE,QAAO,QAAQ,SAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-entry.d.mts","names":[],"sources":["../src/sw-entry.ts"],"mappings":";;;QAMQ,MAAA;EAAA,UACI,MAAA;IACR,OAAA,EAAS,OAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Serwist } from "@serwist/window";
|
|
2
|
+
import { isCurrentPageOutOfScope } from "@serwist/window/internal";
|
|
3
|
+
//#region src/sw-entry.ts
|
|
4
|
+
if (typeof window !== "undefined" && "serviceWorker" in navigator && typeof caches !== "undefined") {
|
|
5
|
+
const scope = self.__SERWIST_SW_ENTRY.scope;
|
|
6
|
+
let swEntryWorker;
|
|
7
|
+
if (self.__SERWIST_SW_ENTRY.swEntryWorker) swEntryWorker = new Worker(self.__SERWIST_SW_ENTRY.swEntryWorker);
|
|
8
|
+
window.serwist = new Serwist(window.location.origin + self.__SERWIST_SW_ENTRY.sw, { scope });
|
|
9
|
+
if (self.__SERWIST_SW_ENTRY.register && !isCurrentPageOutOfScope(scope)) window.serwist.register();
|
|
10
|
+
if (self.__SERWIST_SW_ENTRY.cacheOnNavigation) {
|
|
11
|
+
const cacheOnNavigation = async (url) => {
|
|
12
|
+
if (!window.navigator.onLine || !url) return;
|
|
13
|
+
swEntryWorker?.postMessage({
|
|
14
|
+
type: "__FRONTEND_NAV_CACHE__",
|
|
15
|
+
url
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const pushState = history.pushState;
|
|
19
|
+
history.pushState = (...args) => {
|
|
20
|
+
pushState.apply(history, args);
|
|
21
|
+
cacheOnNavigation(args[2]);
|
|
22
|
+
};
|
|
23
|
+
const replaceState = history.replaceState;
|
|
24
|
+
history.replaceState = (...args) => {
|
|
25
|
+
replaceState.apply(history, args);
|
|
26
|
+
cacheOnNavigation(args[2]);
|
|
27
|
+
};
|
|
28
|
+
window.addEventListener("online", () => {
|
|
29
|
+
cacheOnNavigation(window.location.pathname);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (self.__SERWIST_SW_ENTRY.reloadOnOnline) window.addEventListener("online", () => location.reload());
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export {};
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=sw-entry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-entry.mjs","names":[],"sources":["../src/sw-entry.ts"],"sourcesContent":["import { Serwist } from \"@serwist/window\";\nimport { isCurrentPageOutOfScope } from \"@serwist/window/internal\";\n\nimport type { SerwistNextOptions } from \"./internal-types.js\";\nimport type { MessageType } from \"./sw-entry-worker.js\";\n\ndeclare global {\n interface Window {\n serwist: Serwist;\n }\n}\ndeclare const self: Window &\n typeof globalThis & {\n // Do not dereference this, use its attributes directly or assign them to other variables.\n // You should do the latter if you use an attribute multiple times.\n __SERWIST_SW_ENTRY: SerwistNextOptions;\n };\n\nif (typeof window !== \"undefined\" && \"serviceWorker\" in navigator && typeof caches !== \"undefined\") {\n const scope = self.__SERWIST_SW_ENTRY.scope;\n\n let swEntryWorker: Worker | undefined;\n\n if (self.__SERWIST_SW_ENTRY.swEntryWorker) {\n swEntryWorker = new Worker(self.__SERWIST_SW_ENTRY.swEntryWorker);\n }\n\n window.serwist = new Serwist(window.location.origin + self.__SERWIST_SW_ENTRY.sw, { scope });\n\n if (self.__SERWIST_SW_ENTRY.register && !isCurrentPageOutOfScope(scope)) {\n window.serwist.register();\n }\n\n if (self.__SERWIST_SW_ENTRY.cacheOnNavigation) {\n const cacheOnNavigation = async (url?: string | URL | null | undefined) => {\n if (!window.navigator.onLine || !url) {\n return;\n }\n swEntryWorker?.postMessage({\n type: \"__FRONTEND_NAV_CACHE__\",\n url,\n } satisfies MessageType);\n };\n\n const pushState = history.pushState;\n history.pushState = (...args) => {\n pushState.apply(history, args);\n cacheOnNavigation(args[2]);\n };\n\n const replaceState = history.replaceState;\n history.replaceState = (...args) => {\n replaceState.apply(history, args);\n cacheOnNavigation(args[2]);\n };\n\n window.addEventListener(\"online\", () => {\n cacheOnNavigation(window.location.pathname);\n });\n }\n\n if (self.__SERWIST_SW_ENTRY.reloadOnOnline) {\n window.addEventListener(\"online\", () => location.reload());\n }\n}\n"],"mappings":";;;AAkBA,IAAI,OAAO,WAAW,eAAe,mBAAmB,aAAa,OAAO,WAAW,aAAa;CAClG,MAAM,QAAQ,KAAK,mBAAmB;CAEtC,IAAI;AAEJ,KAAI,KAAK,mBAAmB,cAC1B,iBAAgB,IAAI,OAAO,KAAK,mBAAmB,cAAc;AAGnE,QAAO,UAAU,IAAI,QAAQ,OAAO,SAAS,SAAS,KAAK,mBAAmB,IAAI,EAAE,OAAO,CAAC;AAE5F,KAAI,KAAK,mBAAmB,YAAY,CAAC,wBAAwB,MAAM,CACrE,QAAO,QAAQ,UAAU;AAG3B,KAAI,KAAK,mBAAmB,mBAAmB;EAC7C,MAAM,oBAAoB,OAAO,QAA0C;AACzE,OAAI,CAAC,OAAO,UAAU,UAAU,CAAC,IAC/B;AAEF,kBAAe,YAAY;IACzB,MAAM;IACN;IACD,CAAuB;;EAG1B,MAAM,YAAY,QAAQ;AAC1B,UAAQ,aAAa,GAAG,SAAS;AAC/B,aAAU,MAAM,SAAS,KAAK;AAC9B,qBAAkB,KAAK,GAAG;;EAG5B,MAAM,eAAe,QAAQ;AAC7B,UAAQ,gBAAgB,GAAG,SAAS;AAClC,gBAAa,MAAM,SAAS,KAAK;AACjC,qBAAkB,KAAK,GAAG;;AAG5B,SAAO,iBAAiB,gBAAgB;AACtC,qBAAkB,OAAO,SAAS,SAAS;IAC3C;;AAGJ,KAAI,KAAK,mBAAmB,eAC1B,QAAO,iBAAiB,gBAAgB,SAAS,QAAQ,CAAC"}
|