cache-headers.ts
This file
Path
apps/web/src/server/cache-headers.ts
33 lines · 1.7 KiB · TypeScript
Last changed by
Merge perf/workers-cache into mainoscabrielbefore adoptionccd5da2
History of this fileTake it
Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215
lines 1–8why, one step back1/**2 * The `Cache-Control` a page's route gives (its `headers`), by what the3 * page is addressed by. Only a document's own response carries these:4 * the hashed assets get theirs from `public/_headers`.5 *6 * - A page at `main` or a tag changes with the next landing: a browser7 * keeps it for 30 seconds and may show it for five minutes more while it8 * asks again. No `s-maxage`: a shared cache that honours it stops servingMerge fix/w12-reviewoscabrielbefore adoption7b8b393
lines 9–13why, one step back9 * stale while it asks. A code page at a full commit id is kept the same10 * way: the commit never changes, but the page also carries its landing,11 * which the project records after main has moved (a read between the two12 * finds none), and times reckoned from when it was read. What does not13 * change is kept below the page, by object id (ADR 0019, ADR 0020).Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215
lines 14–15why, one step back14 * - A page about the person reading it (Today, a decision, a proposal) is15 * kept nowhere.Merge perf/workers-cache into mainoscabrielbefore adoptionccd5da2
lines 16–24why, one step back16 *17 * Workers Cache keeps these at the edge too, shared by every reader, keyed18 * by path and query and never by cookie (ADR 0026). So a page that gives19 * `branchPage` reads as nobody: its loader never reaches the reader's20 * request, and its markup is the same for everyone. The Worker's entry21 * (`edge-cache.ts`) has the last word on every answer: one to a request22 * that carries a cookie is kept nowhere whatever its route says, and one23 * the edge may keep varies by `Cookie`, so it reaches only a reader with24 * none (`test/edge-cache.test.ts`).Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215
lines 25–33why, one step back25 */2627export const branchPage = {28 "Cache-Control": "public, max-age=30, stale-while-revalidate=300",29} as const satisfies Readonly<Record<string, string>>;3031export const personalPage = {32 "Cache-Control": "private, no-store",33} as const satisfies Readonly<Record<string, string>>;