---

title: "CDN 缓存策略:s-maxage 与 Surrogate-Control 的取舍"

keywords:

  • s-maxage
  • Surrogate-Control
  • 共享缓存
  • CDN
  • Cache-Control
  • 代理

description: "解释 s-maxage 在共享缓存中的语义与与 max-age 的区别,梳理 Surrogate-Control 在不同 CDN 的兼容性现状,并给出工程落地建议。"

categories:

  • 文章资讯
  • 技术教程

---

概述

s-maxage 用于共享缓存(CDN/代理),覆盖 max-age 的新鲜期;私有缓存忽略该指令。历史上的 Surrogate-Control 在不同 CDN 间存在实现差异。建议优先使用标准 Cache-Control 指令,并在必要时参考各 CDN 的文档兼容策略。

指令语义

  • s-maxage=<秒>:仅作用于共享缓存,并覆盖 max-age/Expires;私有缓存忽略[参考1,3]。
  • max-age=<秒>:作用于所有缓存;若存在 s-maxage,共享缓存以 s-maxage 为准[参考1,3]。

Surrogate-Control 与兼容

  • 作为起源侧对代理/CDN的“代理控制”头,不同厂商存在不兼容实现;Akamai/Fastly/Cloudflare 联合推动更统一的“Targeted Cache Control”方向[参考2]。
  • 具体 CDN 对 Cache-Control 支持范围存在差异(如部分产品仅支持 max-age),需按产品文档与测试确认[参考4]。

落地建议

  • 起源统一使用标准 Cache-Controls-maxage/max-age/must-revalidate 等);在 CDN 层进行规则补充。
  • 对共享缓存与私有缓存的时效区分:入口文档较短时效,子资源长时效;必要时以 s-maxage 调整边缘行为。

参考与验证

  • [参考1]MDN:Cache-Control 文档(s-maxage 语义与覆盖关系):https://mdn.org.cn/en-US/docs/Web/HTTP/Headers/Cache-Control
  • [参考2]Akamai 博客:Targeted Cache Control 与 Surrogate-Control 兼容性讨论:https://www.akamai.com/blog/news/targeted-cache-control
  • [参考3]MDN 中文:Cache-Control 指令说明(must-revalidate/s-maxage 等):https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Reference/Headers/Cache-Control
  • [参考4]Microsoft Q&A:Azure CDN 对指令支持差异说明(产品差异):https://learn.microsoft.com/en-us/answers/questions/316956/azure-cdn-should-respect-origin-cache-control

关键词校验

关键词与 CDN 缓存策略一致。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部