向响应添加 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; }