fix(files): cache the site's media for a year (#62980)

This commit is contained in:
Adam
2026-11-09 16:38:25 -06:00
committed by GitHub
Unverified
parent 0a812d4d70
commit 9a3d87d55d
2 changed files with 5 additions and 2 deletions
+2 -1
View File
@@ -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`.
+3 -1
View File
@@ -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")