レスポンスに Cache-Control ヘッダーを追加する - Amazon CloudFront

レスポンスに Cache-Control ヘッダーを追加する

次のビューワーレスポンス関数は、レスポンスに Cache-Control HTTP ヘッダーを追加します。ヘッダーは max-age ディレクティブを使用して、最大 2 年 (63,072,000 秒) の応答をキャッシュするようにウェブブラウザに指示します。詳細については、MDN Web Docs の Web サイトの「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; }