Skip to main content

CDN Integration

PRISM works well with CDNs for edge caching of rendered pages. This page covers cache keying, Vary headers, and provider-specific configuration.

Cache Keying with X-Prism-Variant

When viewport-aware rendering is enabled, PRISM returns an X-Prism-Variant header (mobile or desktop). Your CDN must use this header to maintain separate caches per device class. Otherwise, a mobile-rendered page may be served to desktop bots or vice versa.

Vary Header

The simplest approach is to add X-Prism-Variant to the Vary response header. Most CDNs respect Vary for cache keying:

Vary: X-Prism-Variant

Your reverse proxy should add this header. See the Reverse Proxy page for examples.

PRISM Cache Headers

PRISM includes these headers on rendered responses:

HeaderDescription
X-Prism-CacheCache status: HIT, MISS, STALE, or BYPASS
X-Prism-Render-TimeRender duration in ms (on MISS only)
X-Prism-VariantDevice class: mobile or desktop
Cache-ControlSynthesized from configured TTL if origin did not provide one

Cloudflare

Cache Rules

Create a Cache Rule to vary by the X-Prism-Variant header:

  1. Go to Caching > Cache Rules.
  2. Create a rule matching your rendered paths (e.g., hostname equals example.com).
  3. Under Cache key, add Header > X-Prism-Variant.

Page Rules (Legacy)

If using legacy Page Rules, Cloudflare does not support custom Vary headers. Use a Cache Rule or a Worker instead.

Worker-Based Cache Key

For full control, use a Cloudflare Worker to include the variant in the cache key:

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
const variant = request.headers.get('X-Prism-Variant') || 'desktop';
const cacheKey = new Request(request.url + '?_variant=' + variant, request);
return fetch(cacheKey);
}

Fastly

VCL Configuration

In vcl_recv, add the variant to the hash:

sub vcl_hash {
set req.hash += req.http.X-Prism-Variant;
}

Or use the Vary header approach -- Fastly respects Vary by default.

Surrogate Keys

For targeted purging, PRISM's response URLs can be used as surrogate keys. Configure Fastly to purge by URL pattern when content changes.

Akamai

Property Manager

  1. Add a Modify Outgoing Response Header behavior to include Vary: X-Prism-Variant.
  2. Or use a Cache ID Modification behavior to add the X-Prism-Variant header value to the cache key.

Cache Key

In your property configuration:

Cache Key: URL + X-Prism-Variant header

Bot-Only Mode CDN Considerations

In bot-only mode, only bot requests are rendered. This means:

  • Bot traffic hits PRISM, gets rendered HTML, and the CDN caches it.
  • Human traffic bypasses PRISM and gets the SPA shell directly from the origin.

If your CDN caches both bot and human responses at the same URL, you need to ensure they are cached separately. Options:

1. Separate Bot Traffic at the CDN Edge

Route bot traffic to PRISM and human traffic directly to the origin at the CDN level. Most CDNs can match User-Agent patterns in routing rules.

2. Don't CDN-Cache PRISM Responses

If bot traffic volume is low, skip CDN caching for rendered pages and let PRISM's built-in cache handle it:

Cache-Control: private, no-store

Adding Vary: User-Agent causes the CDN to create a separate cache entry for every unique User-Agent string, which effectively disables caching. Avoid this approach.

Cache Purging

When content changes on your origin, purge both PRISM's internal cache and your CDN cache:

  1. PRISM cache: Send a POST to the admin API:

    curl -X POST http://localhost:9090/cache/purge -d '{"pattern": "/products/*"}'
  2. CDN cache: Use your CDN provider's purge API. If using viewport-aware rendering, remember to purge both mobile and desktop variants.