向响应添加 Cache-Control 标头 - Amazon CloudFront
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

向响应添加 Cache-Control 标头

以下查看器响应函数将 Cache-Control HTTP 标头添加到响应中。该标头使用 max-age 指令告诉 Web 浏览器将响应最多缓存两年(63072000 秒)。有关更多信息,请参阅 MDN Web Docs 网站上的 Cache-Control

在 GitHub 上查看此示例

JavaScript runtime 2.0
async function handler(event) { const response = event.response; const headers = response.headers; // Set the cache-control header headers['cache-control'] = {value: 'public, max-age=63072000'}; // Return response to viewers return response; }
JavaScript runtime 1.0
function handler(event) { var response = event.response; var headers = response.headers; // Set the cache-control header headers['cache-control'] = {value: 'public, max-age=63072000'}; // Return response to viewers return response; }