Loading...
Loading...
Compare original and translation side by side
max-age=0, must-revalidatemax-age=0, must-revalidate| Header | Who sees it | Use case |
|---|---|---|
| Netlify CDN only (stripped before browser) | CDN-only caching |
| All CDN caches (stripped before browser) | Multi-CDN setups |
| Browser and all caches | General caching |
| 头信息 | 可见对象 | 使用场景 |
|---|---|---|
| 仅Netlify CDN(返回浏览器前会被移除) | 仅CDN端缓存 |
| 所有CDN缓存(返回浏览器前会被移除) | 多CDN部署场景 |
| 浏览器及所有缓存 | 通用缓存配置 |
// Cache at CDN for 1 hour, browser always revalidates
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, s-maxage=3600, must-revalidate",
"Cache-Control": "public, max-age=0, must-revalidate",
},
});
// Stale-while-revalidate (serve stale for 2 min while refreshing)
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, max-age=60, stale-while-revalidate=120",
},
});
// Durable cache (shared across edge nodes, serverless functions only)
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, durable, max-age=60, stale-while-revalidate=120",
},
});// CDN端缓存1小时,浏览器始终重新验证
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, s-maxage=3600, must-revalidate",
"Cache-Control": "public, max-age=0, must-revalidate",
},
});
// Stale-while-revalidate(返回过期内容的同时刷新缓存,最长2分钟)
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, max-age=60, stale-while-revalidate=120",
},
});
// 持久缓存(跨边缘节点共享,仅适用于无服务器函数)
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, durable, max-age=60, stale-while-revalidate=120",
},
});undefinedundefinedundefinedundefinedreturn new Response(body, {
headers: {
"Netlify-Cache-ID": "product,listing",
"Netlify-CDN-Cache-Control": "public, s-maxage=86400",
},
});import { purgeCache } from "@netlify/functions";
export default async () => {
await purgeCache({ tags: ["product"] });
return new Response("Purged", { status: 202 });
};await purgeCache();Netlify-Cache-IDreturn new Response(body, {
headers: {
"Netlify-Cache-ID": "product,listing",
"Netlify-CDN-Cache-Control": "public, s-maxage=86400",
},
});import { purgeCache } from "@netlify/functions";
export default async () => {
await purgeCache({ tags: ["product"] });
return new Response("已清除缓存", { status: 202 });
};await purgeCache();Netlify-Cache-IDreturn new Response(body, {
headers: {
"Netlify-Vary": "cookie=ab_test|is_logged_in",
// Other options: query=param1|param2, header=X-Custom, country=us|de, language=en|fr
},
});return new Response(body, {
headers: {
"Netlify-Vary": "cookie=ab_test|is_logged_in",
// 其他选项:query=param1|param2, header=X-Custom, country=us|de, language=en|fr
},
});revalidatePathrevalidateTagrevalidatePathrevalidateTagNetlify-CDN-Cache-ControlNetlify-CDN-Cache-ControlrouteRulesswrisrrouteRulesswrisrCache-StatusHITMISSREVALIDATEDCache-StatusHITMISSREVALIDATEDNetlify-VaryNetlify-Vary