@serwist/next 9.0.0-preview.0 → 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/index.d.ts.map +1 -1
- package/dist/index.js +33 -710
- package/dist/index.worker.d.ts +2 -3
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +176 -178
- package/dist/internal-types.d.ts +1 -1
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/sw-entry.js +5 -5
- package/dist/worker/constants.d.ts +6 -0
- package/dist/worker/constants.d.ts.map +1 -0
- package/dist/worker/defaultCache.d.ts +14 -2
- package/dist/worker/defaultCache.d.ts.map +1 -1
- package/package.json +21 -14
- package/src/index.ts +27 -21
- package/src/index.worker.ts +2 -3
- package/src/internal-types.ts +1 -1
- package/src/sw-entry.ts +5 -5
- package/src/worker/constants.ts +5 -0
- package/src/worker/defaultCache.ts +175 -152
- package/dist/worker/definePageRuntimeCaching.d.ts +0 -16
- package/dist/worker/definePageRuntimeCaching.d.ts.map +0 -1
- package/src/worker/definePageRuntimeCaching.ts +0 -36
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
|
|
@@ -5,8 +6,7 @@ import type { NextInjectManifestOptions } from "@serwist/build";
|
|
|
5
6
|
import { validateNextInjectManifestOptions } from "@serwist/build/next";
|
|
6
7
|
import { InjectManifest } from "@serwist/webpack-plugin";
|
|
7
8
|
import { ChildCompilationPlugin, relativeToOutputPath } from "@serwist/webpack-plugin/internal";
|
|
8
|
-
import {
|
|
9
|
-
import fg from "fast-glob";
|
|
9
|
+
import { globSync } from "glob";
|
|
10
10
|
import type { NextConfig } from "next";
|
|
11
11
|
import type { Compilation, Configuration, default as Webpack } from "webpack";
|
|
12
12
|
|
|
@@ -27,7 +27,7 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
|
|
|
27
27
|
const tsConfigJson = loadTSConfig(options.dir, nextConfig?.typescript?.tsconfigPath);
|
|
28
28
|
|
|
29
29
|
const {
|
|
30
|
-
|
|
30
|
+
cacheOnNavigation,
|
|
31
31
|
disable,
|
|
32
32
|
scope = basePath,
|
|
33
33
|
swUrl,
|
|
@@ -59,7 +59,7 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
|
|
|
59
59
|
new webpack.DefinePlugin({
|
|
60
60
|
"self.__SERWIST_SW_ENTRY.sw": `'${_sw}'`,
|
|
61
61
|
"self.__SERWIST_SW_ENTRY.scope": `'${_scope}'`,
|
|
62
|
-
"self.__SERWIST_SW_ENTRY.
|
|
62
|
+
"self.__SERWIST_SW_ENTRY.cacheOnNavigation": `${cacheOnNavigation}`,
|
|
63
63
|
"self.__SERWIST_SW_ENTRY.register": `${register}`,
|
|
64
64
|
"self.__SERWIST_SW_ENTRY.reloadOnOnline": `${reloadOnOnline}`,
|
|
65
65
|
} satisfies Record<`${SerwistNextOptionsKey}.${Exclude<keyof SerwistNextOptions, "swEntryWorker">}`, string | undefined>),
|
|
@@ -100,16 +100,16 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const {
|
|
103
|
-
swSrc:
|
|
104
|
-
swDest:
|
|
103
|
+
swSrc: userSwSrc,
|
|
104
|
+
swDest: userSwDest,
|
|
105
105
|
additionalPrecacheEntries,
|
|
106
|
-
exclude
|
|
106
|
+
exclude,
|
|
107
107
|
manifestTransforms = [],
|
|
108
108
|
...otherBuildOptions
|
|
109
109
|
} = buildOptions;
|
|
110
110
|
|
|
111
|
-
let swSrc =
|
|
112
|
-
let swDest =
|
|
111
|
+
let swSrc = userSwSrc;
|
|
112
|
+
let swDest = userSwDest;
|
|
113
113
|
|
|
114
114
|
// If these two paths are not absolute, they will be resolved from `compilation.options.output.path`,
|
|
115
115
|
// which is `${options.dir}/${nextConfig.destDir}` for Next.js apps, rather than `${options.dir}`
|
|
@@ -122,9 +122,21 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
const publicDir = path.resolve(options.dir, "public");
|
|
125
|
-
const destDir = path.
|
|
125
|
+
const { dir: destDir, base: destBase } = path.parse(swDest);
|
|
126
|
+
|
|
127
|
+
const cleanUpList = globSync(["swe-worker-*.js", "swe-worker-*.js.map", destBase, `${destBase}.map`], {
|
|
128
|
+
absolute: true,
|
|
129
|
+
nodir: true,
|
|
130
|
+
cwd: destDir,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
for (const file of cleanUpList) {
|
|
134
|
+
fs.rm(file, { force: true }, (err) => {
|
|
135
|
+
if (err) throw err;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
126
138
|
|
|
127
|
-
const shouldBuildSWEntryWorker =
|
|
139
|
+
const shouldBuildSWEntryWorker = cacheOnNavigation;
|
|
128
140
|
let swEntryPublicPath: string | undefined = undefined;
|
|
129
141
|
let swEntryWorkerDest: string | undefined = undefined;
|
|
130
142
|
|
|
@@ -150,28 +162,22 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
|
|
|
150
162
|
logger.info(` URL: ${_sw}`);
|
|
151
163
|
logger.info(` Scope: ${_scope}`);
|
|
152
164
|
|
|
153
|
-
config.plugins.push(
|
|
154
|
-
new CleanWebpackPlugin({
|
|
155
|
-
cleanOnceBeforeBuildPatterns: [path.join(destDir, "swe-worker-*.js"), path.join(destDir, "swe-worker-*.js.map"), swDest],
|
|
156
|
-
}),
|
|
157
|
-
);
|
|
158
|
-
|
|
159
165
|
// Precache files in public folder
|
|
160
166
|
let resolvedManifestEntries = additionalPrecacheEntries;
|
|
161
167
|
|
|
162
168
|
if (!resolvedManifestEntries) {
|
|
163
|
-
const swDestFileName = path.basename(swDest);
|
|
164
169
|
const userPublicGlob = typeof globPublicPatterns === "string" ? [globPublicPatterns] : globPublicPatterns ?? ["**/*"];
|
|
165
|
-
const publicScan =
|
|
170
|
+
const publicScan = globSync(
|
|
166
171
|
[
|
|
167
172
|
...userPublicGlob,
|
|
168
173
|
// Forcibly include these in case the user outputs these files to `public`.
|
|
169
174
|
"!swe-worker-*.js",
|
|
170
175
|
"!swe-worker-*.js.map",
|
|
171
|
-
`!${
|
|
172
|
-
`!${
|
|
176
|
+
`!${destBase}`,
|
|
177
|
+
`!${destBase}.map`,
|
|
173
178
|
],
|
|
174
179
|
{
|
|
180
|
+
nodir: true,
|
|
175
181
|
cwd: publicDir,
|
|
176
182
|
},
|
|
177
183
|
);
|
package/src/index.worker.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
+
import { PAGES_CACHE_NAME } from "./worker/constants.js";
|
|
1
2
|
import { defaultCache } from "./worker/defaultCache.js";
|
|
2
|
-
import { type DefinePageRuntimeCachingOptions, type PageRuntimeCaching, definePageRuntimeCaching } from "./worker/definePageRuntimeCaching.js";
|
|
3
3
|
|
|
4
|
-
export { defaultCache,
|
|
5
|
-
export type { DefinePageRuntimeCachingOptions, PageRuntimeCaching };
|
|
4
|
+
export { defaultCache, PAGES_CACHE_NAME };
|
package/src/internal-types.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type SerwistNextOptionsKey = "self.__SERWIST_SW_ENTRY";
|
|
|
5
5
|
export interface SerwistNextOptions {
|
|
6
6
|
sw: string;
|
|
7
7
|
scope: string;
|
|
8
|
-
|
|
8
|
+
cacheOnNavigation: boolean;
|
|
9
9
|
register: boolean;
|
|
10
10
|
reloadOnOnline: boolean;
|
|
11
11
|
swEntryWorker: string | undefined;
|
package/src/sw-entry.ts
CHANGED
|
@@ -30,8 +30,8 @@ if (typeof window !== "undefined" && "serviceWorker" in navigator && typeof cach
|
|
|
30
30
|
window.serwist.register();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
if (self.__SERWIST_SW_ENTRY.
|
|
34
|
-
const
|
|
33
|
+
if (self.__SERWIST_SW_ENTRY.cacheOnNavigation) {
|
|
34
|
+
const cacheOnNavigation = async (url?: string | URL | null | undefined) => {
|
|
35
35
|
if (!window.navigator.onLine || !url) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
@@ -44,17 +44,17 @@ if (typeof window !== "undefined" && "serviceWorker" in navigator && typeof cach
|
|
|
44
44
|
const pushState = history.pushState;
|
|
45
45
|
history.pushState = (...args) => {
|
|
46
46
|
pushState.apply(history, args);
|
|
47
|
-
|
|
47
|
+
cacheOnNavigation(args[2]);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
const replaceState = history.replaceState;
|
|
51
51
|
history.replaceState = (...args) => {
|
|
52
52
|
replaceState.apply(history, args);
|
|
53
|
-
|
|
53
|
+
cacheOnNavigation(args[2]);
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
window.addEventListener("online", () => {
|
|
57
|
-
|
|
57
|
+
cacheOnNavigation(window.location.pathname);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -1,144 +1,160 @@
|
|
|
1
|
+
import { ExpirationPlugin } from "@serwist/expiration";
|
|
2
|
+
import { RangeRequestsPlugin } from "@serwist/range-requests";
|
|
3
|
+
import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "@serwist/strategies";
|
|
1
4
|
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
-
import { definePageRuntimeCaching } from "./definePageRuntimeCaching.js";
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
import { PAGES_CACHE_NAME } from "./constants.js";
|
|
7
|
+
|
|
8
|
+
// Serwist RuntimeCaching config: https://serwist.pages.dev/docs/sw/register-runtime-caching
|
|
5
9
|
export const defaultCache = [
|
|
6
10
|
{
|
|
7
|
-
|
|
8
|
-
handler:
|
|
9
|
-
options: {
|
|
11
|
+
matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
|
|
12
|
+
handler: new CacheFirst({
|
|
10
13
|
cacheName: "google-fonts-webfonts",
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
plugins: [
|
|
15
|
+
new ExpirationPlugin({
|
|
16
|
+
maxEntries: 4,
|
|
17
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
}),
|
|
16
21
|
},
|
|
17
22
|
{
|
|
18
|
-
|
|
19
|
-
handler:
|
|
20
|
-
options: {
|
|
23
|
+
matcher: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
|
|
24
|
+
handler: new StaleWhileRevalidate({
|
|
21
25
|
cacheName: "google-fonts-stylesheets",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
plugins: [
|
|
27
|
+
new ExpirationPlugin({
|
|
28
|
+
maxEntries: 4,
|
|
29
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
30
|
+
}),
|
|
31
|
+
],
|
|
32
|
+
}),
|
|
27
33
|
},
|
|
28
34
|
{
|
|
29
|
-
|
|
30
|
-
handler:
|
|
31
|
-
options: {
|
|
35
|
+
matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
|
36
|
+
handler: new StaleWhileRevalidate({
|
|
32
37
|
cacheName: "static-font-assets",
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
plugins: [
|
|
39
|
+
new ExpirationPlugin({
|
|
40
|
+
maxEntries: 4,
|
|
41
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
}),
|
|
38
45
|
},
|
|
39
46
|
{
|
|
40
|
-
|
|
41
|
-
handler:
|
|
42
|
-
options: {
|
|
47
|
+
matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
|
48
|
+
handler: new StaleWhileRevalidate({
|
|
43
49
|
cacheName: "static-image-assets",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
plugins: [
|
|
51
|
+
new ExpirationPlugin({
|
|
52
|
+
maxEntries: 64,
|
|
53
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
}),
|
|
49
57
|
},
|
|
50
58
|
{
|
|
51
|
-
|
|
52
|
-
handler:
|
|
53
|
-
options: {
|
|
59
|
+
matcher: /\/_next\/static.+\.js$/i,
|
|
60
|
+
handler: new CacheFirst({
|
|
54
61
|
cacheName: "next-static-js-assets",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
plugins: [
|
|
63
|
+
new ExpirationPlugin({
|
|
64
|
+
maxEntries: 64,
|
|
65
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
}),
|
|
60
69
|
},
|
|
61
70
|
{
|
|
62
|
-
|
|
63
|
-
handler:
|
|
64
|
-
options: {
|
|
71
|
+
matcher: /\/_next\/image\?url=.+$/i,
|
|
72
|
+
handler: new StaleWhileRevalidate({
|
|
65
73
|
cacheName: "next-image",
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
plugins: [
|
|
75
|
+
new ExpirationPlugin({
|
|
76
|
+
maxEntries: 64,
|
|
77
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
}),
|
|
71
81
|
},
|
|
72
82
|
{
|
|
73
|
-
|
|
74
|
-
handler:
|
|
75
|
-
options: {
|
|
76
|
-
rangeRequests: true,
|
|
83
|
+
matcher: /\.(?:mp3|wav|ogg)$/i,
|
|
84
|
+
handler: new CacheFirst({
|
|
77
85
|
cacheName: "static-audio-assets",
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
plugins: [
|
|
87
|
+
new ExpirationPlugin({
|
|
88
|
+
maxEntries: 32,
|
|
89
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
90
|
+
}),
|
|
91
|
+
new RangeRequestsPlugin(),
|
|
92
|
+
],
|
|
93
|
+
}),
|
|
83
94
|
},
|
|
84
95
|
{
|
|
85
|
-
|
|
86
|
-
handler:
|
|
87
|
-
options: {
|
|
88
|
-
rangeRequests: true,
|
|
96
|
+
matcher: /\.(?:mp4|webm)$/i,
|
|
97
|
+
handler: new CacheFirst({
|
|
89
98
|
cacheName: "static-video-assets",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
plugins: [
|
|
100
|
+
new ExpirationPlugin({
|
|
101
|
+
maxEntries: 32,
|
|
102
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
103
|
+
}),
|
|
104
|
+
new RangeRequestsPlugin(),
|
|
105
|
+
],
|
|
106
|
+
}),
|
|
95
107
|
},
|
|
96
108
|
{
|
|
97
|
-
|
|
98
|
-
handler:
|
|
99
|
-
options: {
|
|
109
|
+
matcher: /\.(?:js)$/i,
|
|
110
|
+
handler: new StaleWhileRevalidate({
|
|
100
111
|
cacheName: "static-js-assets",
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
plugins: [
|
|
113
|
+
new ExpirationPlugin({
|
|
114
|
+
maxEntries: 48,
|
|
115
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
116
|
+
}),
|
|
117
|
+
],
|
|
118
|
+
}),
|
|
106
119
|
},
|
|
107
120
|
{
|
|
108
|
-
|
|
109
|
-
handler:
|
|
110
|
-
options: {
|
|
121
|
+
matcher: /\.(?:css|less)$/i,
|
|
122
|
+
handler: new StaleWhileRevalidate({
|
|
111
123
|
cacheName: "static-style-assets",
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
124
|
+
plugins: [
|
|
125
|
+
new ExpirationPlugin({
|
|
126
|
+
maxEntries: 32,
|
|
127
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
128
|
+
}),
|
|
129
|
+
],
|
|
130
|
+
}),
|
|
117
131
|
},
|
|
118
132
|
{
|
|
119
|
-
|
|
120
|
-
handler:
|
|
121
|
-
options: {
|
|
133
|
+
matcher: /\/_next\/data\/.+\/.+\.json$/i,
|
|
134
|
+
handler: new NetworkFirst({
|
|
122
135
|
cacheName: "next-data",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
plugins: [
|
|
137
|
+
new ExpirationPlugin({
|
|
138
|
+
maxEntries: 32,
|
|
139
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
140
|
+
}),
|
|
141
|
+
],
|
|
142
|
+
}),
|
|
128
143
|
},
|
|
129
144
|
{
|
|
130
|
-
|
|
131
|
-
handler:
|
|
132
|
-
options: {
|
|
145
|
+
matcher: /\.(?:json|xml|csv)$/i,
|
|
146
|
+
handler: new NetworkFirst({
|
|
133
147
|
cacheName: "static-data-assets",
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
plugins: [
|
|
149
|
+
new ExpirationPlugin({
|
|
150
|
+
maxEntries: 32,
|
|
151
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
152
|
+
}),
|
|
153
|
+
],
|
|
154
|
+
}),
|
|
139
155
|
},
|
|
140
156
|
{
|
|
141
|
-
|
|
157
|
+
matcher: ({ sameOrigin, url: { pathname } }) => {
|
|
142
158
|
// Exclude /api/auth/callback/* to fix OAuth workflow in Safari without having an impact on other environments
|
|
143
159
|
// The above route is the default for next-auth, you may need to change it if your OAuth workflow has a different callback route
|
|
144
160
|
// Issue: https://github.com/shadowwalker/next-pwa/issues/131#issuecomment-821894809
|
|
@@ -152,72 +168,79 @@ export const defaultCache = [
|
|
|
152
168
|
|
|
153
169
|
return false;
|
|
154
170
|
},
|
|
155
|
-
handler: "NetworkFirst",
|
|
156
171
|
method: "GET",
|
|
157
|
-
|
|
172
|
+
handler: new NetworkFirst({
|
|
158
173
|
cacheName: "apis",
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
174
|
+
plugins: [
|
|
175
|
+
new ExpirationPlugin({
|
|
176
|
+
maxEntries: 16,
|
|
177
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
178
|
+
}),
|
|
179
|
+
],
|
|
163
180
|
networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
|
|
164
|
-
},
|
|
181
|
+
}),
|
|
165
182
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
183
|
+
{
|
|
184
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) =>
|
|
185
|
+
request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
186
|
+
handler: new NetworkFirst({
|
|
187
|
+
cacheName: PAGES_CACHE_NAME.rscPrefetch,
|
|
188
|
+
plugins: [
|
|
189
|
+
new ExpirationPlugin({
|
|
173
190
|
maxEntries: 32,
|
|
174
191
|
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
}),
|
|
193
|
+
],
|
|
194
|
+
}),
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
198
|
+
handler: new NetworkFirst({
|
|
199
|
+
cacheName: PAGES_CACHE_NAME.rsc,
|
|
200
|
+
plugins: [
|
|
201
|
+
new ExpirationPlugin({
|
|
183
202
|
maxEntries: 32,
|
|
184
203
|
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
}),
|
|
205
|
+
],
|
|
206
|
+
}),
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) =>
|
|
210
|
+
request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
|
|
211
|
+
handler: new NetworkFirst({
|
|
212
|
+
cacheName: PAGES_CACHE_NAME.html,
|
|
213
|
+
plugins: [
|
|
214
|
+
new ExpirationPlugin({
|
|
194
215
|
maxEntries: 32,
|
|
195
216
|
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
},
|
|
199
|
-
}
|
|
217
|
+
}),
|
|
218
|
+
],
|
|
219
|
+
}),
|
|
220
|
+
},
|
|
200
221
|
{
|
|
201
|
-
|
|
202
|
-
handler:
|
|
203
|
-
options: {
|
|
222
|
+
matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith("/api/"),
|
|
223
|
+
handler: new NetworkFirst({
|
|
204
224
|
cacheName: "others",
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
225
|
+
plugins: [
|
|
226
|
+
new ExpirationPlugin({
|
|
227
|
+
maxEntries: 32,
|
|
228
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
229
|
+
}),
|
|
230
|
+
],
|
|
231
|
+
}),
|
|
210
232
|
},
|
|
211
233
|
{
|
|
212
|
-
|
|
213
|
-
handler:
|
|
214
|
-
options: {
|
|
234
|
+
matcher: ({ sameOrigin }) => !sameOrigin,
|
|
235
|
+
handler: new NetworkFirst({
|
|
215
236
|
cacheName: "cross-origin",
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
237
|
+
plugins: [
|
|
238
|
+
new ExpirationPlugin({
|
|
239
|
+
maxEntries: 32,
|
|
240
|
+
maxAgeSeconds: 60 * 60, // 1 hour
|
|
241
|
+
}),
|
|
242
|
+
],
|
|
220
243
|
networkTimeoutSeconds: 10,
|
|
221
|
-
},
|
|
244
|
+
}),
|
|
222
245
|
},
|
|
223
246
|
] satisfies RuntimeCaching[];
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
-
export interface PageRuntimeCaching extends Omit<RuntimeCaching, "options"> {
|
|
3
|
-
options?: Omit<NonNullable<RuntimeCaching["options"]>, "cacheName">;
|
|
4
|
-
}
|
|
5
|
-
export interface DefinePageRuntimeCachingOptions {
|
|
6
|
-
rscPrefetch?: PageRuntimeCaching;
|
|
7
|
-
rsc?: PageRuntimeCaching;
|
|
8
|
-
html?: PageRuntimeCaching;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Conveniently define three `runtimeCaching` entries for Next.js pages.
|
|
12
|
-
* @param options
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare const definePageRuntimeCaching: ({ rscPrefetch, rsc, html }: DefinePageRuntimeCachingOptions) => RuntimeCaching[];
|
|
16
|
-
//# sourceMappingURL=definePageRuntimeCaching.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"definePageRuntimeCaching.d.ts","sourceRoot":"","sources":["../../src/worker/definePageRuntimeCaching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;IACzE,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;CACrE;AAED,MAAM,WAAW,+BAA+B;IAC9C,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,GAAG,CAAC,EAAE,kBAAkB,CAAC;IACzB,IAAI,CAAC,EAAE,kBAAkB,CAAC;CAC3B;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,+BAAgC,+BAA+B,KAAG,cAAc,EAiBpH,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
-
import { nonNullable } from "@serwist/utils";
|
|
3
|
-
|
|
4
|
-
export interface PageRuntimeCaching extends Omit<RuntimeCaching, "options"> {
|
|
5
|
-
options?: Omit<NonNullable<RuntimeCaching["options"]>, "cacheName">;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface DefinePageRuntimeCachingOptions {
|
|
9
|
-
rscPrefetch?: PageRuntimeCaching;
|
|
10
|
-
rsc?: PageRuntimeCaching;
|
|
11
|
-
html?: PageRuntimeCaching;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Conveniently define three `runtimeCaching` entries for Next.js pages.
|
|
16
|
-
* @param options
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
export const definePageRuntimeCaching = ({ rscPrefetch, rsc, html }: DefinePageRuntimeCachingOptions): RuntimeCaching[] => {
|
|
20
|
-
const pageRcs = [rscPrefetch, rsc, html] as RuntimeCaching[];
|
|
21
|
-
|
|
22
|
-
if (pageRcs[0]) {
|
|
23
|
-
if (!pageRcs[0].options) pageRcs[0].options = {};
|
|
24
|
-
pageRcs[0].options.cacheName = "pages-rsc-prefetch";
|
|
25
|
-
}
|
|
26
|
-
if (pageRcs[1]) {
|
|
27
|
-
if (!pageRcs[1].options) pageRcs[1].options = {};
|
|
28
|
-
pageRcs[1].options.cacheName = "pages-rsc";
|
|
29
|
-
}
|
|
30
|
-
if (pageRcs[2]) {
|
|
31
|
-
if (!pageRcs[2].options) pageRcs[2].options = {};
|
|
32
|
-
pageRcs[2].options.cacheName = "pages";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return pageRcs.filter(nonNullable);
|
|
36
|
-
};
|