maximize Cloudflare edge caching

This commit is contained in:
2569718930@qq.com
2026-06-10 19:11:58 +08:00
parent 081bf9cc05
commit 1494db8e09
18 changed files with 421 additions and 42 deletions
+28 -3
View File
@@ -3,15 +3,40 @@ const nextConfig = {
output: "standalone",
reactStrictMode: true,
async headers() {
const cacheHeader = {
const immutableCacheHeader = {
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
};
const immutableCloudflareCacheHeader = {
key: "Cloudflare-CDN-Cache-Control",
value: "public, max-age=31536000, immutable",
};
const publicPageHeaders = [
{
key: "Cache-Control",
value: "public, max-age=0, s-maxage=600, stale-while-revalidate=3600",
},
{
key: "Cloudflare-CDN-Cache-Control",
value: "public, max-age=600, stale-while-revalidate=3600",
},
];
const staticExts = ["jpg", "jpeg", "png", "gif", "ico", "svg", "webp", "avif", "woff2", "ttf", "eot", "css", "js"];
return staticExts.map((ext) => ({
const staticAssetRules = staticExts.map((ext) => ({
source: `/:path(.+\\.${ext})`,
headers: [cacheHeader],
headers: [immutableCacheHeader, immutableCloudflareCacheHeader],
}));
const publicPageRules = [
"/",
"/docs/:path*",
"/modern/:path*",
"/probabilities/:path*",
"/subscription-help/:path*",
].map((source) => ({
source,
headers: publicPageHeaders,
}));
return [...staticAssetRules, ...publicPageRules];
},
};