maximize Cloudflare edge caching
This commit is contained in:
@@ -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];
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user