Home » Blog » Performance » CDN Caching Strategies for Dynamic Websites That Work
CDN Caching Strategies for Dynamic Websites That Work
Share this post:
For a dynamic website, the first caching decision is which responses are safe to share. Cache-key design comes next. Public pages can sometimes share an edge response even when requests carry different tracking parameters, but private or authenticated content needs a separate policy. A higher hit ratio is useful only when the cache continues to return the right response to the right visitor.
Why Dynamic Does Not Always Mean Uncacheable
A public product listing or editorial page may remain identical across many requests for a short period. Where the application’s freshness requirements allow it, a short TTL can absorb bursts without keeping content stale for long. Five to thirty seconds can be a starting point for a test, not a universal safe setting: inventory, pricing, permissions, and personalized responses may require different treatment.
Do not put an account page, cart, payment flow, or personalized dashboard into a shared cache simply because much of its layout looks common. Bypass shared caching for private responses and use appropriate private or no-store directives. If a dashboard contains public data, consider caching that public component separately. Removing an authorization header or session cookie from a key does not make an authenticated response safe to share.
Cache-Key Design Is a Route-Level Decision
Normalize only the inputs proven not to affect the response
On a public route, irrelevant query parameters can create multiple cache entries for the same content. Compare the origin responses before changing the key. Tracking parameters such as utm_source may be removable after testing, while search terms, filters, language, currency, and version parameters may change the response and must remain distinct. Authentication and session handling belong in the cache-eligibility policy as well as the key design.
For static assets, content-hashed filenames make versioning explicit. If an existing deployment uses a query parameter such as ?v=123 to identify a new asset, retain that parameter until the versioning scheme changes. Ignoring every query string can otherwise serve an old file after a deployment. Check the CDN’s actual defaults and rule precedence instead of assuming every provider builds keys in the same way.
Invalidation and the Thundering Herd
Use stale responses only where the application permits them
Versioned asset URLs avoid many invalidation problems. For mutable public content, a supported cache-tag or URL purge can invalidate a bounded group of responses without clearing the entire site. Define that group around the content dependency, then test that updates reach all affected routes.
When a popular entry expires, concurrent misses can increase origin load. Request collapsing and stale-while-revalidate can help, subject to provider behavior and response directives. They do not guarantee one origin request across the entire CDN. Do not allow stale responses where correctness requires immediate revocation or current transactional data. Verify expiry, background refresh, and origin-error behavior under load rather than treating stale-while-revalidate as a default for every route.
Engineering Judgment: What to Measure
Start with the highest-traffic public routes. Record cache eligibility, key inputs, TTL, invalidation triggers, and the maximum acceptable staleness for each. Measure hit ratio alongside origin requests, response correctness, and tail latency. Include tests with two different user sessions, query variations, a content update, and an origin failure. An improved hit ratio is not a successful rollout if a response leaks across users or remains stale beyond its allowed window.
SIRAYA recommends treating cache policy as part of application behavior: establish the privacy boundary first, normalize public keys deliberately, and validate performance against the workload that the origin actually serves.
Technical References
Provider behavior checked on December 1, 2026: Cloudflare cache-control behavior and Google Cloud CDN caching and request collapsing. Confirm the settings supported by your own CDN and plan before applying them.