Cache headers, CDN rules and invalidation for public pages and the app
Use this policy to cache public pages and static files at the edge, keep unhashed files on revalidate, cache content hashed files for one year, and keep every signed-in screen and every API response on private no-store, so workspace data is never served from a shared cache. Headers are set by the Worker on the response. A page tag is not a substitute for a response header.
How to read this policy
Scope is the site part in pack app-permitdesk.site.1. That part states no response header for any path. The table below is the rule to apply in the Worker for each path class in that pack. Where the live host header is not in this pack, treat the live value as unknown until a header check confirms it.
- Public means the response may be stored by a shared cache and by a browser, with the Cache-Control and CDN rule in the table. Private means the response may be stored only by the browser that requested it, with private no-store in the table.
- No-store means the response is not stored by a browser or a shared cache. The next request fetches it again. Use no-store for any response that depends on sign-in, workspace, role or a status link code.
- Must-revalidate means a stored response must be checked with the server before it is used again. Keep must-revalidate on every public HTML page and on every unhashed file.
- Immutable means a stored response is used without a check until its max-age ends. Use immutable only where the filename contains a content hash, so a new deploy creates a new filename. Never use immutable on a filename that does not change between versions.
- Vary names the request fields that change the response. Vary Cookie and Authorization tells a shared cache that the same URL can return different workspace data for different sign-ins, so the shared cache must not store the response.
Cache rule by path class
Work down the table in order. Apply the first row that matches the path. Do not widen a row to a path that does not match it.
| Path class | Cache-Control on the response | CDN rule and Vary | Invalidation on deploy |
|---|---|---|---|
| Public HTML, one page per file. Home, features, permits, inspections, licensing-planning, reports-setup, portal, security, accessibility, about, request-demo, notifications, analytics, status page shell, health page shell, offline page shell, 404 page and every guide under guides | public, max-age=3600, s-maxage=7200, stale-while-revalidate=86400, must-revalidate | Store at the edge for s-maxage. Vary Accept, Accept-Language. Do not vary by Cookie, because the page does not depend on sign-in. A page must return the same HTML for every visitor. | Purge the HTML paths on deploy. The purge covers the exact paths in this row. Do not purge hashed assets in the same action. |
| Unhashed files that do not change name between versions. Theme, site styles, site script, app styles and app script | public, max-age=3600, must-revalidate. No immutable. No long s-maxage. | Store at the edge only while the revalidate check passes. Vary Accept-Encoding. Return ETag or Last-Modified with every response, so a check can return 304 where the file is unchanged. | No purge. The revalidate check picks up the new file within max-age. Do not set a long max-age to work around a missing purge, because a later change would not reach visitors. |
| Content hashed files under assets, where the filename contains a hash of the file content | public, max-age=31536000, immutable | Store at the edge for one year. No Vary beyond Accept-Encoding. The hash in the filename is the cache key. | No purge. A deploy that changes the file creates a new filename and a new link. The old filename may stay cached until it expires. |
| Icons and manifest. Icons folder and manifest webmanifest | public, max-age=86400, must-revalidate. Use immutable only where the icon filename contains a hash. | Store at the edge for one day with revalidate. Vary Accept-Encoding. | Revalidate on deploy. Do not purge hashed icon files. |
| Signed-in app shell and views. App folder and every path under it | private, no-store, no-cache, must-revalidate | Never store at the edge. Vary Cookie, Authorization, Accept. The shell and every view depend on sign-in and workspace selection, so a shared cache must not store them. | No purge. The browser fetches the shell again on every load. Do not add a public rule for this path to speed up sign-in. |
| Every API path. Public request post, public record status lookup, files and every signed-in list, detail, report, export and setup call | private, no-store, no-cache, must-revalidate | Never store at the edge, with or without a query string. Vary Cookie, Authorization, Accept. A status lookup code, a files ref and a workspace filter must never be part of a shared cache key. | No purge. No API response is kept, so no stale record, fee, document or status can be served. A post is never cached. |
| Service worker file and health probe. Service worker file at root, dedicated health address and its fallback home fetch | For the service worker file, public, max-age=0, must-revalidate. For the health address, private, no-store. | Never serve a cached service worker file for more than one check. Never cache a health result, because a cached ok result would hide a down site. Vary Accept. | Request the service worker file with a revalidate check on every app load, so a new version is found. Do not purge the service worker file by a long cache rule. |
Rules that keep private and workspace data out of a shared cache
These rules apply on top of the table above, with no exception for a single page.
- Never use public on an app or API response, even where the page that calls it is public. The demo form page is public HTML, its post to the public request endpoint is private no-store.
- Never cache a response that sets a cookie, depends on a cookie, or returns workspace fields, record fields, fee fields, document names, message text or account fields.
- Never cache a status lookup by code, a files list by ref, or any list that uses Text, Status, Record type, Date, Owner or Workspace filters, even where the filters are blank.
- Never cache a response with a query string that carries a code, a token, a ref or a health probe marker. Requests with a health probe marker bypass the edge cache and the browser cache, and the response is no-store.
- Never put a code, a token, an email, a phone, a parcel, a record number or a support code in a cache key, in a log field or in a page tag. The page path only is safe in a log.
- Keep the signed-in shell on noindex in addition to private no-store. Noindex controls search indexing. It does not replace the cache rule.
CDN key, compression and range rules
Use the same key for every public HTML page and every unhashed file, so a fix in one place covers the site.
| Item | Rule for public paths | Rule for app and API paths |
|---|---|---|
| Cache key | Full path, scheme and host, without fragment. Query string is part of the key only where the page states it, and a health probe query bypasses the cache. | No shared cache key. Each request is fetched from the origin and is not stored. |
| Vary and encoding | Vary Accept-Encoding, so compressed and uncompressed copies do not mix. Serve the same compressed file to every visitor. | No shared copy exists, so encoding does not create a shared entry. |
| Range and partial content | Allow range requests on hashed files and icons only, where the file is large. Do not allow range on a public HTML page. | Do not allow a range request to create a shared partial entry for app or API data. |
| ETag and Last-Modified | Return a strong ETag or Last-Modified on every public HTML page and every unhashed file, so revalidate can return 304. | Return no ETag that a shared cache can use to serve a stored copy. The response is no-store. |
| Preload and preconnect | Use preload for the style and script that the page needs on first load only. Do not preload a file that the page does not need. | Do not preload app or API data on a public page. |
Invalidation in order on deploy
Run these steps in order for each deploy. Each step ends with what you should see when it worked.
Purge public HTML only
Purge the paths in the public HTML row and no other row. You should see the new HTML on the next request, with the same Cache-Control in the table.
Leave hashed files alone
Do not purge a hashed asset. The new deploy links to a new filename, so visitors pick it up without a purge. You should see the old hashed file still fast until it expires, and the new hashed file served from the edge.
Let unhashed files revalidate
Do not set a long max-age on an unhashed path to avoid a purge. You should see the browser check with If-None-Match or If-Modified-Since and receive 200 with the new file or 304 where the file did not change.
Confirm app and API need no purge
Check that the app shell and the API return private no-store in the response header. You should see no stored copy at the edge, so a deploy needs no app or API purge and no workspace data can go stale.
Run the public liveness check and the signed-in checks separately
Open the site status check with no sign-in and run a liveness check. Then sign in, confirm the workspace name and the role shown on the account, and open one list and one record. You should see a public result and a signed-in result, reported as separate lines, in the same way as on the status check page.
Site status check - API authorization rules - Unified API response contract - Security
Set up the headers in order
Work through these steps in order before you rely on a cache rule in production.
Set the public HTML rule in the Worker
Apply the Cache-Control and Vary values from the table for public HTML. You should see the header on a plain page load with no sign-in.
Set the unhashed and hashed asset rules
Apply must-revalidate with no immutable to unhashed paths, and immutable with a one year max-age to hashed paths only. You should see the two rules differ on the header check, with ETag or Last-Modified on the unhashed path.
Set private no-store for the app and every API path
Apply private no-store and Vary Cookie, Authorization, Accept to the app folder and to every API path, including the public status lookup and the files list. You should see private no-store on a signed-in list, on a status lookup and on a files list, with no shared cache entry.
Test a private lookup with no cache
Open a test record, run a status lookup, change the record, then run the same lookup again. You should see the new status on the second run, which proves the first response was not stored.
Test a draft and a test record stay out of public search and out of cache
Search public search with the test record number. You should see no draft and no test record, and no cached public copy of a private field.
Publish only after the header check passes
Run the safe defaults health check in the setup guide, then publish. Do not rely on a page tag in place of a response header.
- Unknown: Worker header values on the live host not in supplied site pack. Record the header check result with the workspace name and check time in setup notes before you rely on a rule.
- Unknown: CDN provider name, edge locations and purge API not in supplied site pack. Record the provider, the purge path and the tested purge result with the town office before live use.
- Unknown: service worker update behavior beyond the max-age zero rule in this table, where the service worker file itself is not in this pack. Do not add a second service worker path.
Bring your path list to the demo
Tell us which public page or signed-in list you want to check first, and we will run the header check with you.