CDN Integration
A CDN must distinguish rendered bot HTML from the human SPA shell, and mobile from desktop representations. A shared URL alone is not a sufficient cache key.
Request keys, not response headers
X-Prism-Variant is a diagnostic response header: bot-mobile,
bot-desktop, human-mobile, or human-desktop. It is unavailable when the
CDN looks up an incoming request. Do not add it to a request cache key or to
Vary: absent request values would collapse the representations together.
PRISM advertises Vary: User-Agent when the User-Agent can change the body.
Eligible bypassed responses declare the same dimensions as rendered responses.
Routes that never render, such as excluded assets, do not add that dimension.
PRISM also declares Accept and Accept-Encoding; preserve origin Vary
dimensions as well.
What PRISM tells a shared cache
When the origin sends no Cache-Control, PRISM adds one to rendered responses,
controlled by cache.synthesize_cache_control:
| Mode | Default (true) sends | Why |
|---|---|---|
bot-only | private, max-age=<ttl> | A URL has two representations: rendered HTML for crawlers and your origin's own page for visitors. Only Vary: User-Agent separates them, and several CDNs ignore Vary. |
render-all | public, max-age=<ttl>, s-maxage=<ttl> | Every client gets the same rendered page. |
false adds nothing, "public" always sends the public form and "private"
always sends the private form. A Cache-Control the origin sends is passed on
as it is, whatever the setting.
If a CDN caches HTML in front of a bot-only site
A private response is not stored by a compliant shared cache, but PRISM
cannot make a CDN comply, and a cache rule such as "cache everything" or
"override origin TTL" ignores private as well. If your CDN caches HTML, do one
of these:
- Bypass the CDN cache for crawler requests, and for all HTML if you cannot tell the classes apart.
- Key the cache on the crawler class (see below), after checking that your CDN really uses the key.
Without one of these, the CDN can store the crawler's script-free HTML and serve it to visitors, or serve your single-page shell to crawlers.
When "public" is the right setting
Use cache.synthesize_cache_control = "public" in bot-only mode only when the
CDN keys its cache on the crawler class or on User-Agent, and you have run
the checks in Verify before enabling caching.
Then s-maxage lets the edge keep each representation for as long as PRISM
does. In render-all mode the default is already public.
Origins that declare their pages public
The setting changes only what PRISM synthesizes. If your origin itself sends
Cache-Control: public (or s-maxage), PRISM passes that header on for the
rendered response too, and the same risk applies: a CDN that ignores Vary can
store the crawler HTML under it. Give such an origin the same treatment: bypass
or key the CDN cache for HTML in bot-only mode.
The origin's header is also passed on for a render PRISM itself declined to
store: an incomplete render under
render.incomplete_ttl_secs = 0,
or a response to an authenticated request. PRISM keeps no copy, but a CDN that
honours the origin's public can. PRISM sends no-store on such a response
only when the origin sent no Cache-Control at all. If your origin marks
pages public, do not let the CDN cache rendered HTML unless you accept that.
Start with a safe policy
For renderable HTML in bot-only mode, bypass the CDN cache until you have verified a suitable
request key. PRISM's internal render cache can still serve repeated crawls.
Do not enable a broad “cache everything” rule that stores the human shell and
later serves it to bots.
If your CDN supports it, key on the incoming User-Agent plus the URL (including
query), Accept, Accept-Encoding, and all other response-varying request
fields. This is conservative and can fragment the cache. Verify your provider's
actual behavior: declaring Vary alone does not guarantee the CDN honors it.
Optional normalized request key
For better cache reuse, an edge classifier can overwrite a request header such
as X-Render-Class with one of the four bot/human and mobile/desktop combinations.
Never trust a client-supplied value. Classifying only device type is insufficient
in bot-only mode: desktop humans and desktop bots receive different bodies.
[cache]
vary = ["x-render-class"]
The name must not begin with x-prism-; PRISM reserves those names and rejects
them as cache-key dimensions. Configuring cache.vary makes PRISM include the
request header in its cache key, forward it to Chromium, and advertise it in
Vary. It does not replace PRISM's bot detector or remove its User-Agent
Vary dimension.
Configure the CDN's custom request key to include X-Render-Class before its
cache lookup. Keep the classifier aligned with PRISM's configured bot patterns,
device detection, and any explicit render overrides. A short example regex is
not an equivalent classifier. If you cannot guarantee agreement, retain the
full User-Agent key or bypass edge caching. Also separate any other inputs that
change the body; never share authenticated or personalized responses publicly.
Provider setup
Cloudflare
Use a request-header cache key only if your plan and rules support it. Populate
X-Render-Class before lookup and forward it to PRISM. A Worker can implement
that flow, but its cache key must be separate from the origin request URL:
do not append a synthetic variant query to the URL sent to your application.
Do not select X-Prism-Variant as a request header in Cache Rules. If the
required key cannot be configured, bypass caching for renderable HTML.
Fastly
Populate the normalized request header in vcl_recv and include
req.http.X-Render-Class in the cache hash, alongside the existing host, URL,
and other required dimensions. Use the complete classifier described above.
Do not hash req.http.X-Prism-Variant, which is normally absent. Keep PRISM's
cache.vary configuration aligned with the injected header.
Akamai
Compute the normalized request header before cache lookup and use it in
Cache ID Modification, preserving the existing URL and other dimensions.
Adding Vary: X-Prism-Variant through an outgoing response-header behavior
does not create a usable request key. Bypass HTML caching if the property
cannot reliably distinguish the representations.
Verify before enabling caching
On a test route with visible JavaScript-generated content:
- Request as a human first, then a desktop bot, then a mobile bot. Confirm the bot responses contain rendered content rather than the human shell.
- Purge and repeat in the reverse order. Confirm humans still receive the intended application response.
- Repeat each request and inspect the CDN's cache-status headers. Check that the second request hits only its own representation.
- Repeat with query strings, configured vary headers, and render overrides. Verify authenticated requests bypass shared caching.
X-Prism-Cache reports PRISM's HIT, MISS, STALE, or BYPASS status;
it does not report a CDN hit. X-Prism-Render-Time reports render duration on a
miss. Inspect X-Prism-Variant on rendered responses to diagnose classification,
but never use it as an incoming key.
Cache purging
Purge PRISM and the CDN when origin content changes:
# Set PRISM_ADMIN_TOKEN to the token configured in [admin].bearer_token.
curl -fsS -X POST http://127.0.0.1:4001/purge/pattern \
-H "Authorization: Bearer $PRISM_ADMIN_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"pattern":"/products/*"}'
Then use your CDN's purge mechanism to remove all corresponding request-key variants, including bot/human and mobile/desktop. Purging only PRISM leaves already cached edge responses intact.