Railway CDN Cache Demo

Interactive demo of HTTP caching strategies. Each endpoint uses a different Cache-Control pattern. Hit the buttons and watch the origin hit count — cached responses won't increment it.

Origin Hit Counts

Click "Refresh Stats" to load

Immutable Static Asset

GET /api/static-asset
Cache-Control: public, max-age=31536000, immutable
Cached for 1 year. Perfect for hashed/fingerprinted assets (JS bundles, CSS, images). The CDN and browser will never revalidate.

Short CDN Cache + SWR

GET /api/short-cache
Cache-Control: public, s-maxage=10, stale-while-revalidate=30
CDN caches for 10s, then serves stale for up to 30s while revalidating. Users never wait on the origin after the first request.

HTML Page Cache + ETag

GET /api/page-cache
Cache-Control: public, s-maxage=300, stale-while-revalidate=3600
5-minute CDN cache with 1-hour SWR window. Also includes an ETag for conditional revalidation — when the CDN checks the origin, it may get a 304 (no body).

Private / No Store

GET /api/private
Cache-Control: private, no-store
Never cached by the CDN. Every request reaches the origin. Use for authenticated or user-specific data. Notice the origin hit count always increases.

Vary: Content Negotiation

GET /api/content-negotiation
Cache-Control: public, s-maxage=60 | Vary: Accept
The CDN caches separate entries per Accept header. JSON and HTML requests get different cached responses from the same URL.

Conditional (ETag + Last-Modified)

GET /api/conditional
Cache-Control: public, s-maxage=30, must-revalidate
After 30s, the CDN must revalidate. It sends If-None-Match / If-Modified-Since headers. If content hasn't changed, origin returns 304 with no body.

No Headers (Anti-pattern)

GET /api/no-headers
Cache-Control: (none)
No cache headers set at all. Behavior is undefined — the CDN may apply heuristic caching or skip caching entirely. Always set explicit Cache-Control.

Try it with curl

curl -sI https://your-app.railway.app/api/short-cache | grep -iE "cache-control|age|x-cache|etag"

When deployed on Railway, look for the Age header (seconds since cached), X-Cache (HIT/MISS), and Cache-Control to confirm the CDN is working.