交付缓存
CDN 缓存头规划
选择资源类型并得到 Cache-Control 建议。带 hash 的文件可以用长期 immutable;HTML 和私有 API 应重新验证或禁止共享缓存。
可用100/100
资源类型
文件名带 hash 时可用一年 immutable。HTML 和登录态 API 不行。
方案只留在此浏览器,不会上传。
建议响应头
把 Cache-Control 配到 CDN 或源站对应路径。
| 类型 | 匹配 | Cache-Control |
|---|---|---|
| 带 hash 的 JS/CSS/图片 | /assets/*.[hash].* | public, max-age=31536000, immutable |
| HTML 文档 | / | public, max-age=0, must-revalidate |
| 私有 API | /api/* | private, no-store |
| 字体 | /fonts/*.[hash].woff2 | public, max-age=31536000, immutable |
| 无 hash 图片 | /images/* | public, max-age=86400, stale-while-revalidate=604800 |
| Sitemap XML | /sitemap*.xml | public, max-age=3600, stale-while-revalidate=86400 |