Guides

Cache headers, ETags, and CDN rules by resource class

Use one cache plan for every response. Public pages and static assets are cached so a repeat visit is fast. Signed-in pages and signed-in API responses are never cached by a shared cache, so one person never receives another person or college response. The same file name rule applies on every deploy, with no long lived cache on a file whose name does not change.

Comparison by resource class

Read the class first, then set the headers for that class only. Do not copy a public header to a signed-in route, and do not copy a private header to a public asset.

Cache-Control, ETag, Vary, and CDN behavior by resource class
Resource classExample paths in this siteBrowser Cache-ControlCDN and shared cacheETag and Vary
Public marketing HTML/, /features, /assistants, /reports, /guides/, /guides/payload-performance, and other public pages that hold no signed-in datapublic, max-age=300, must-revalidateCache GET 200 only at the same max-age. No personal data is in the body, so every visitor may reuse the same copy.Strong ETag that changes only when the page content changes. Vary Accept-Encoding only. Do not add Cookie or Authorization to Vary on a public page, because that would split one public copy into one copy per visitor.
Content hashed static files/assets/ followed by a file name with a content hash in itpublic, max-age=31536000, immutableCache GET 200 only for one year. A new build uses a new hashed name, so no purge is needed for the old copy.Strong ETag from the content hash. Vary Accept-Encoding only. Immutable means the browser does not revalidate during that year.
Static files whose name does not change/theme.css, /site.css, /site.js, /icons/icon.svg, /manifest.webmanifest, and guide scripts such as /grounding-guardrail.jspublic, max-age=0, must-revalidateCache GET 200 only with max-age=0 and must-revalidate. The edge revalidates with If-None-Match before it serves a stored copy.Strong ETag from the file content. Vary Accept-Encoding only. Never use a long lived cache on this class, because a later change keeps the same name and must reach visitors on the next load.
Signed-in app pages/app/ and every signed-in screen under it, including Ask, Sources, Assistants, Improve, Reports, Governance, and Teamprivate, no-storeNo shared cache. No CDN cache on any status. The response is built for one signed-in person in one college workspace.No ETag. Do not send If-None-Match handling on this class. Vary Cookie, Authorization, Accept-Encoding as defense in depth, so a shared cache can never treat two people as one.
Authenticated API responsesGET /api/ routes that need sign-in, including workspace list, answer list, source list, question list, reports list, and workspace searchprivate, no-storeNo shared cache. No CDN cache on any status. A smaller payload never reuses a response across people, roles, or colleges.No ETag and no Last-Modified reuse. Vary Cookie, Authorization, Accept-Encoding. Shrink the fields and the page size instead of caching the response, as stated in API payload performance.
Public form, health, and non-GET responsesPOST /api/public/request, GET /api/health, readiness inside the signed-in app, every POST, every redirect, and every 4xx or 5xx responseprivate, no-storeNo shared cache. Cache GET 200 only applies to the three public classes above, and to no other class.No ETag reuse on this class. A health check must be fresh on each run, and a form response must not be replayed from a cache.

Public search on the guides index and on terminology runs in the browser and has no server response to cache. Workspace search is an authenticated API response and follows the authenticated row above, as stated in Search scope.

ETag rules that keep revalidation correct

An ETag lets a repeat visit skip the body when nothing changed. It is a performance tool only on public GET 200 responses.

  • Send a strong ETag only on public GET 200 responses in the first three rows of the table above. Compute it from the response content, so the same content gives the same ETag and changed content gives a different ETag.
  • On a repeat request with If-None-Match carrying the stored ETag, return 304 with no body when the content is unchanged, and return 200 with the new body and a new ETag when the content changed. Keep the same Cache-Control on the 304 as on the 200.
  • Send no ETag on private, no-store, POST, redirect, 4xx, or 5xx responses. Do not accept If-None-Match on those responses as a reason to skip the body.
  • Do not use a weak ETag as the only validator for a public HTML page, and do not use Last-Modified alone, because a deploy time can change without the content changing. Content based ETag plus must-revalidate is the validator for this site.
  • Compression does not change the ETag. Send Vary Accept-Encoding on every compressible public response, so a cache never serves a gzip or brotli body to a browser that did not accept that encoding.

How a repeat visit flows under this plan

Use this flow to check a repeat visit in the network panel. The first visit downloads the body. A later visit revalidates or reuses the stored public copy, and a signed-in visit always goes to the origin.

```mermaid
flowchart TD
  A[Visitor loads a public page] --> B{Has a stored copy with a strong ETag}
  B -->|No| C[Origin returns 200 with body, ETag, and Cache-Control]
  B -->|Yes| D[Browser sends If-None-Match with the stored ETag]
  D --> E{Content unchanged}
  E -->|Yes| F[Origin returns 304 with no body and the visitor reuses the stored copy]
  E -->|No| C
  G[Signed-in page or API request] --> H[Origin returns private, no-store, with no ETag]
  H --> I[No shared cache stores the response and no other person reuses it]
```

Invalidation plan for a deploy

Invalidation follows the file name rule. A hashed name needs no purge. A name that does not change needs revalidation, not a long cache.

  1. Step 1: Ship hashed files under a new name

    Build content hashed files under /assets/ with the hash in the name. The new page points to the new name. Keep the old hashed copy in the cache until it expires, because no live page points to it after the deploy.

  2. Step 2: Rely on must-revalidate for public HTML and unhashed files

    Public HTML uses max-age=300 with must-revalidate. Unhashed files use max-age=0 with must-revalidate. After a deploy, the next load revalidates with If-None-Match and receives either a 304 or the new body, so a change reaches visitors without a manual browser clear.

  3. Step 3: Purge the edge for the changed public paths in the same deploy

    Purge by path for each changed public HTML path and each changed unhashed file path, using the build output list of changed paths. Purge only those paths. Do not purge a signed-in path or an API path, because those paths were never cached by the edge.

  4. Step 4: Keep signed-in and API responses out of the purge list

    A signed-in page and an authenticated API response carry private, no-store and no ETag, so there is no stored copy to purge and no stale copy to remove. A deploy never needs a sign-out or a cache clear to show new signed-in data, because the browser and the edge store nothing.

  5. Step 5: Confirm the new ETag after the deploy

    Load each changed public path with a hard reload, read the new ETag and Cache-Control in the network panel, and confirm a second load sends If-None-Match and receives a 304 when nothing changed again. Record the path, the status, and the ETag for each changed public path.

  • Never add immutable or a one year max-age to /theme.css, /site.css, /site.js, /icons/icon.svg, /manifest.webmanifest, or any other file whose name stays the same between versions.
  • Never add a public Cache-Control to /app/ or to a GET /api/ route that needs sign-in, and never add an ETag to a private, no-store response.
  • Never cache a POST, a redirect, a 4xx, or a 5xx response at the edge, and never serve a stored public copy for a signed-in request.
  • When in doubt about a path, treat it as private, no-store until the path is confirmed to hold no signed-in data and no college workspace data.

Verify the headers before you publish

Run each check with curl and with the browser network panel, on phone and desktop. Replace the path in each command with the path under test and run the command with no secret in the command line.

curl -s -D - https://campus.appmajic.ai/guides/payload-performance -o /dev/null
curl -s -D - https://campus.appmajic.ai/theme.css -o /dev/null
curl -s -D - https://campus.appmajic.ai/assets/example.js -o /dev/null
curl -s -D - https://campus.appmajic.ai/api/health -o /dev/null
  • A public HTML path returns public, max-age=300, must-revalidate, a strong ETag, and Vary Accept-Encoding, with no Cookie in Vary.
  • An unhashed file such as /theme.css returns public, max-age=0, must-revalidate, and a strong ETag, and a repeat request with If-None-Match returns 304 with no body when the file is unchanged.
  • A content hashed file under /assets/ returns public, max-age=31536000, immutable, and a strong ETag.
  • A signed-in page and a signed-in API response return private, no-store, no ETag, and Vary Cookie, Authorization, Accept-Encoding, and a second person or a second college never receives a stored copy of the first response.
  • POST /api/public/request and GET /api/health return private, no-store, and no ETag, and a repeat health check is fresh on each run.
  • A changed public path after a deploy returns a new ETag and the new body, and an unchanged public path returns 304, with the same Cache-Control on the 304 as on the 200.

Follow API payload performance for field selection and pagination, Search scope for public and workspace search caching, Health, liveness, and readiness checks for the health check cache rule, and List pagination, sorting, and filtering for the list contract that keeps a cached page small.

Cache public copies, never private ones

Ship the headers by resource class above, revalidate files whose name does not change, and keep every signed-in response private with no-store.