Caching policy that caches public pages and never caches workspace data
Use one header policy for public marketing pages, static assets, the signed-in app, and API responses. Public approved content is cached at the edge and in the browser. Anything that depends on sign-in, college workspace, role, or assistant is never cached by a shared cache and is not stored by the browser after the session. The same Cache-Control, ETag, CDN, and revalidation rule covers public search result views, the live check and public form endpoint, and the /status page shell, with revalidation for public HTML and unhashed assets and long caching only for content-hashed assets under /assets/.
Audit of the pack as it stands
Each row states what this pack shows today. The app shell, API code, and worker routing are outside this pack, so no header rule for those surfaces is present here. That absence is the gap this policy closes.
| Surface | Headers in the pack today | Risk |
|---|---|---|
| Public marketing and guide pages in public and public/guides, including the /status page shell and public search result views | No Cache-Control, no ETag, and no CDN rule in any file. The HTML is served with no stated freshness, so each visit revalidates or refetches by default. | Slower repeat visits and no stated edge freshness for content that does not change often. |
| Unhashed static assets: theme.css, site.css, site.js, my-answers-store.js, grounding-guardrail.js, icons, manifest | Referenced by a fixed name with no content hash and no header rule. A long-lived cache on a fixed name would keep a changed file for returning visitors. | Stale styles and scripts after a change, with no revalidation signal. |
| Content-hashed assets under assets | No hashed asset path is listed in this pack and no header rule is stated for one. | The safest surface for long caching has no stated rule, so a builder must guess. |
| Signed-in app shell at app and API responses for Ask, Sources, Improve, and Reports | No header rule in this pack. Guides in the pack require one college workspace at a time, role permission per record, and no question text across colleges. | A default shared cache could store a workspace response and serve it to another workspace or role. |
| Device tools such as My Answers and the checklists on guide pages | No server response. Records stay in local storage on this device and nothing is sent to a server. | Low for HTTP caching. The risk is a server rule that cached a page that also sets device state. |
Policy by surface
Apply these header lines at the worker and edge, not in page HTML. A response is classified by what it contains, never by its URL alone. If a response contains workspace data, the private row wins over every public row. Set the headers in this table on every route in the class. Browser values are sent to the browser. CDN values are sent at the edge for shared cache use. A value not in this table is not set. Apply the ETag and revalidation rules below with this table.
| Surface | Cache-Control | ETag and revalidation | CDN rule |
|---|---|---|---|
| Public marketing and guide HTML, with no sign-in and no workspace data, including the /status page shell | public, max-age=3600, stale-while-revalidate=86400, s-maxage=86400 | Strong ETag from the body hash. Honor If-None-Match with 304. Vary: Accept-Encoding only. | Cache GET 200 only. Bypass on Cookie or Authorization. Purge the page on publish. |
| Content-hashed assets, name changes when content changes | public, max-age=31536000, immutable | Strong ETag from the body hash. 304 support is optional because the name already changes. | Cache GET 200 for one year. No purge needed when the name changes. |
| Unhashed assets: theme.css, site.css, site.js, my-answers-store.js, grounding-guardrail.js, icons, manifest | public, max-age=0, must-revalidate | Strong ETag from the body hash. Revalidate on every use and serve 304 when unchanged. | Revalidate at the edge. Do not use a long max-age or immutable on a fixed name. |
| Website widget answer with no session, public approved sources only | public, max-age=60, stale-while-revalidate=300, s-maxage=60, only when the request has no Cookie and no Authorization | Strong ETag keyed by college, assistant, and question record. Never reuse an ETag across colleges. | Cache only the no-session public variant. Any request with a session bypasses the cache and uses the private row. |
| Public search result views: /guides/ with q, and the terminology search view | Browser: public, max-age=0, must-revalidate; CDN: public, max-age=3600, must-revalidate | Strong ETag, Vary: Accept-Encoding | Cache GET 200 only, cache key includes the full query string |
| Live check and public form endpoint: /api/health, /api/public/request, and the live check response on /status | private, no-store | No ETag reuse, Vary: Accept | No CDN cache, no ETag reuse |
| Signed-in app shell at app and any page that renders workspace data | private, no-store | No ETag. A validator must never match a response in another workspace or role. | No cache. Bypass the CDN, or serve the response with no-store so the CDN stores nothing. Vary: Cookie, Authorization. |
| API responses for questions, answers, sources, reports, themes, and team | private, no-store | No ETag on a response that carries question text, answer text, source records, or counts. Conditional requests are not used for workspace data. | No cache. Do not cache POST, errors, 401, or 403. Vary: Cookie, Authorization. |
Session-only mode adds no exception. A session-only workspace still uses the private rows, and the screen states that nothing is kept after the session ends. Unhashed files use a short max age with revalidation only. No immutable and no max-age=31536000 is set on a file whose name does not change between versions, because long-lived caching on those files stops later changes from reaching visitors. Only content-hashed files under /assets/ can be cached long. The CDN value public, max-age=3600, must-revalidate for public search result views matches Search scope and does not apply to assets or to signed-in responses. The live check at /api/health stays reachable with no sign-in, as in Health, liveness, and readiness checks.
Rules that apply on every surface
These rules remove the common ways a cache leaks data or hides a change. Apply every ETag and revalidation rule below with the table above.
ETag rules
- Use a strong ETag computed from the exact body bytes for a public or asset response. Do not use a weak ETag for a public page that carries a source link or a date.
- Generate the ETag per college, per assistant, and per record where the body differs by any of those. The same URL in two workspaces must never share an ETag value.
- Strip ETag and Last-Modified from every private, no-store response. Do not send a validator for a response that must not be stored.
- On If-None-Match, return 304 only for the public and asset rows above, and only when the stored body and the current body are the same bytes.
- Use a strong ETag only on public GET 200 responses in the table above. A matching If-None-Match returns 304 with the same Cache-Control and no body. Never return an ETag for reuse on a private, no-store response, and never use a weak ETag on an authenticated response.
CDN and browser rules
- Cache only GET requests with a 200 response and a public Cache-Control line. Never cache a response with Set-Cookie.
- Bypass the cache on any request with Cookie or Authorization, on any non-GET request, and on any URL under app or api.
- Keep Vary narrow. Use Accept-Encoding on public rows and Cookie with Authorization on private rows. Do not add a broad Vary that splits the public cache by session.
- Purge a public guide page at the edge when that guide is republished. A hashed asset needs no purge. An unhashed asset relies on revalidation, not on a purge.
- Cache at the CDN on GET 200 only for public rows in the table above. Never cache 4xx or 5xx responses at the CDN. Use no stale-while-revalidate and no stale copy on private or signed-in responses.
- Send Vary Accept-Encoding on a public response that can be compressed, so a cache does not serve a compressed body to a browser that did not accept it. Send Vary Cookie, Authorization on signed-in responses, and Vary Accept on the live check response where the response can vary by Accept.
What never caches
If any item below is present in a response, that response uses private, no-store and no ETag, even on a public URL.
- Question text, answer text, source records, theme records, report counts, and team or role records for a workspace
- A handoff reference, a rating, a follow record, a digest line, or an audit entry
- A response that varies by the signed-in account, by role, or by the detail permission for full question text or export
- An error, a redirect that depends on sign-in, a 401, or a 403
- A test or staff preview response, which is labeled as test and excluded from counts
- A live check response at /api/health or a public form response at /api/public/request, which use private, no-store with no CDN cache and no ETag reuse
- A 4xx or 5xx response
Checks before you ship a caching change
Run each check on the production origin and on a staging origin before you publish. Set the headers in the policy table on every route in the class.
- Request a public HTML page and confirm Cache-Control is public, max-age=3600, stale-while-revalidate=86400, s-maxage=86400, a strong ETag is present, and Vary Accept-Encoding is present
- Request /theme.css and /site.css and confirm public, max-age=0, must-revalidate, no immutable, no max-age=31536000, a strong ETag is present, and If-None-Match returns 304
- Request a content-hashed file under /assets/ and confirm public, max-age=31536000, immutable, and a strong ETag
- Request a guides search view with q, and the terminology search view, and confirm browser Cache-Control is public, max-age=0, must-revalidate, the CDN value is public, max-age=3600, must-revalidate, the cache key includes the full query string, and a strong ETag is present
- Request /api/health with no sign-in and confirm private, no-store, no CDN cache, no ETag reuse, and Vary Accept, and confirm the live check stays reachable with no sign-in
- Request /api/public/request and the live check response on /status and confirm private, no-store, no CDN cache, and no ETag reuse
- Request a signed-in app or API response and confirm private, no-store, no CDN cache, and Vary Cookie, Authorization
- Confirm no public page, unhashed asset, or search view returns immutable with a filename that does not change, and no signed-in response is cached for reuse across people
- Confirm /theme.css and /site.css are preloaded with rel preload as style fetchpriority high, and use a strong ETag only on public GET 200 responses
Check the policy for a surface on this page
Choose a surface. The tool shows the header lines from the policy table above. Nothing entered here is sent to a server.
Choose a surface, then choose Show header lines.
The tool copies the policy table. It does not set any header.
- A public guide returns public, max-age=3600 with a strong ETag and a 304 on a matching If-None-Match
- A hashed asset returns public, max-age=31536000, immutable, and an unhashed asset returns public, max-age=0, must-revalidate with a strong ETag
- The app shell and every API response return private, no-store, no ETag, and Vary: Cookie, Authorization, and a second workspace cannot read the first workspace response from a shared cache
- A request with a session cookie to the widget bypasses the public cache and returns the private row
- A changed unhashed file reaches a returning visitor on the next visit, and a changed guide is purged at the edge on publish
- A public search result view returns browser public, max-age=0, must-revalidate and CDN public, max-age=3600, must-revalidate with a cache key that includes the full query string
- /api/health with no sign-in returns private, no-store, no CDN cache, and no ETag reuse
Next guide
Keep search scope and workspace isolation consistent with this cache rule. Keep payloads small, then check the headers on each resource class.