From 9a3d87d55d77c6c93638b77c4583cdab45e6f49f Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:38:25 -0600 Subject: [PATCH] fix(files): cache the site's media for a year (#62980) --- services/files/README.md | 3 ++- services/files/src/index.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/services/files/README.md b/services/files/README.md index 64ad379cd16..05ec972ecc4 100644 --- a/services/files/README.md +++ b/services/files/README.md @@ -55,7 +55,8 @@ Set HTTP metadata when uploading: `application/gzip`. Missing types default to `application/octet-stream`. - `Content-Disposition`: use `attachment; filename="..."` when a file should download rather than display inline. -- `Cache-Control`: defaults to `public, max-age=3600` (one hour). Use +- `Cache-Control`: defaults to `public, max-age=3600` (one hour), or a year + (`immutable`) under `site/`, whose files never change in place. Use `public, max-age=31536000, immutable` for versioned/content-addressed files, and a short TTL or `no-store` for mutable pointers such as `latest.json`. diff --git a/services/files/src/index.ts b/services/files/src/index.ts index c9061479456..fe34d3f3ce8 100644 --- a/services/files/src/index.ts +++ b/services/files/src/index.ts @@ -77,7 +77,9 @@ export default { headers.set("Last-Modified", object.uploaded.toUTCString()) headers.set("Accept-Ranges", "bytes") if (!headers.has("Content-Type")) headers.set("Content-Type", "application/octet-stream") - if (!headers.has("Cache-Control")) headers.set("Cache-Control", "public, max-age=3600") + // The site's media never changes in place: a changed file gets a new dated folder (services/site/MEDIA.md). + if (!headers.has("Cache-Control")) + headers.set("Cache-Control", key.startsWith("site/") ? "public, max-age=31536000, immutable" : "public, max-age=3600") const modified = Math.floor(object.uploaded.getTime() / 1000) * 1000 const ifMatch = request.headers.get("If-Match")