Server & Hosting Performance

CDN and edge caching explained: faster delivery with safe cache rules

A nearby cache helps only when it holds the right response and can safely reuse it.

A distant origin connected to several edge nodes serving nearby points on an abstract map
Illustration: edge nodes can serve reusable content closer to visitors.

A content delivery network can improve website delivery by serving reusable responses from locations nearer to visitors and reducing repeated requests to the origin. It helps most when the resources that delay a page are cacheable and the chosen edge actually has a usable copy. A CDN does not automatically fix slow application code, large images or expensive JavaScript, and full-page caching requires stricter rules than caching public static assets.

Follow one request from visitor to origin

The browser first connects to the CDN endpoint. The edge checks whether the request matches an eligible stored response and whether that response can be reused. A fresh hit can be served without fetching the resource from the origin. A miss may require an origin request, after which the edge decides whether the returned response is eligible for storage.

An expired object is not always equivalent to an empty cache. The CDN may validate it, fetch a replacement or serve it under a supported stale-response policy. The result depends on headers and provider configuration. Read the service's cache-status documentation rather than treating every value that is not HIT as the same event.

A CDN can also terminate TLS, deliver HTTP/2 or HTTP/3, compress resources or transform images. These capabilities are separate from cache hits and may require explicit settings or a particular service tier. They do not guarantee that a request becomes faster. A nearby visitor with an already fast origin, or a page that always bypasses caching, may gain little from an extra delivery layer.

Use the server response time guide to separate connection delay, origin processing and response delivery. That distinction helps determine whether the CDN is addressing the actual bottleneck. A fast stylesheet hit cannot compensate for an HTML request still waiting on an expensive database operation.

Establish what is cached by default

There is no universal CDN default. Many services cache common public assets such as images, CSS and JavaScript, while HTML and API responses require suitable headers or rules. Others apply different defaults according to the product, origin type or cache mode. File extensions alone are not proof that a response is stored, and a cacheable response is not proof that it will remain resident.

Inspect the documentation and a representative response for each content class. Record the cache key, accepted methods, eligible status codes, treatment of cookies and authorization, freshness policy and behavior after expiry. A setting that sounds like cache everything must not be enabled across account pages simply because it improves a test page's response time.

These patterns have different operational requirements.

Pattern Reason to use it Required control
Public fingerprinted assets Reuse identical files across visitors Change URL when bytes change
Public HTML with edge caching Avoid repeated page generation Explicit eligibility, freshness and invalidation
Personalized pages that bypass shared caches Keep user-specific responses isolated Session and authorization checks
Public shell plus private data requests Share stable layout while protecting data Private endpoints, safe rendering and correct authentication

The browser caching guide covers the client's separate cache. Keep the two policies coordinated: a CDN purge cannot reliably revoke an asset that a browser is still allowed to reuse locally.

Define a key that represents the actual response

A cache key decides which requests may share a stored object. It commonly includes the host, path and some or all query parameters, with additional variation according to service rules. If language, currency or image dimensions change the response, the relevant difference must be represented in the key or excluded from shared caching.

Ignoring tracking parameters may consolidate genuinely identical public responses. Ignoring every query parameter can instead merge a filtered page, a different image transformation or a signed request with something else. Make normalization an allowlist decision supported by application behavior. The fact that a parameter looks unimportant is not evidence that the backend ignores it.

The opposite error is an unnecessarily fragmented key. Including a unique visitor identifier on a response that is identical for everyone prevents useful sharing. Including the entire Cookie header can create a separate object for many combinations. Prefer a small, explicit set of public variants when that is truly how the application works; keep private account data out of that scheme.

Write down two requests that should share a response and two that must not. Test those pairs before launch and after changes to personalization. This simple review connects abstract cache configuration to the content a visitor could actually receive.

Give public HTML an explicit freshness policy

Only cache HTML at the edge after confirming that it contains no session-specific identity, account data, private tokens or other personalized output. Restrict eligible routes and methods, and bypass authenticated requests and relevant session cookies. Ensure the provider respects origin private and no-store directives; an override that ignores them defeats the protection.

For genuinely public HTML, this illustrative header separates browser freshness from shared-cache freshness.

http
Cache-Control: public, max-age=0, s-maxage=300

The browser's stored response is immediately stale, while a compliant shared cache can regard it as fresh for 300 seconds, subject to HTTP age calculations and the rest of the policy. These values are an example, not a recommended lifetime for every publication. Choose the edge lifetime from the acceptable delay in showing an update and the reliability of your invalidation process.

For sensitive personalized output, use a restrictive origin response and an explicit CDN bypass rule.

http
Cache-Control: no-store

Do not strip Set-Cookie just to make a response cacheable without understanding why the application set it. Likewise, do not assume every cookie-bearing request is private: an analytics cookie may not change a public page. The correct rule follows the application response, but ambiguous cases should remain outside shared caching until verified.

Measure cache effectiveness with a defined denominator

A request hit ratio divides cache hits by the requests included in the report. Providers may count eligible requests, all requests or particular status classes differently. Read the definition before comparing dashboards. A byte hit ratio measures delivered bytes from cache and answers a different question from the fraction of requests served as hits.

Segment results by HTML, images and other assets, and by geography where useful. An excellent asset hit ratio can hide almost no HTML reuse. A page requested once at many edge locations may repeatedly miss even while a popular file stays warm. Long lifetimes do not prevent eviction, and a larger network does not guarantee that every object is cached near every user.

Compare hits, misses and bypasses with TTFB, origin request volume and user-facing page timing. Distinguish a cold first request after deployment from steady traffic. Do not repeatedly reload a single warm URL and treat the fastest response as the experience of the whole audience. The PageSpeed analyzer can support a controlled page check, but it is not a CDN-wide hit-ratio report.

Purge precisely and deploy in a safe order

For fingerprinted assets, publishing a new URL is usually simpler than replacing an object in place. Upload the new files before publishing HTML that references them. Keep earlier files available for old pages and open sessions. An edge purge is not a replacement for this versioning discipline.

For stable HTML URLs, choose invalidation by URL or, where supported, by a content tag that groups dependent pages. Updating an article can affect its category, homepage and related-content blocks. The invalidation plan should cover those dependencies without unnecessarily evicting every unrelated asset.

A broad purge can create a burst of misses and origin work. Establish who can trigger it, what happens if the purge fails and how stale delivery is detected. Test the entire publication path, including preview and rollback, rather than only the API response announcing that a purge request was accepted. Distributed invalidation behavior and completion guarantees vary by service.

Some providers offer origin shielding, where edge misses pass through an additional cache layer. That can consolidate origin requests, but introduces another layer to understand during diagnosis and invalidation. It is useful only when the workload and configuration justify it; an extra cache is not automatically an improvement.

Recognize errors caused by overlapping layers

Double caching often means that a hosting cache, CDN cache and browser cache each have a different idea of freshness. Record which layer generated the response and which layers reused it. An Age header can help show stored-response age, but provider-specific status fields need their own documentation. Do not infer the whole path from a single header.

Check that HTTPS, host redirects and canonical routing do not add avoidable trips before the useful response. Keep the origin certificate and origin authentication configured even when visitors connect only to the CDN. A faster edge connection does not make an exposed or incorrectly routed origin acceptable.

Image transformation services create additional variants by size, format and quality. Include the transformation in the cache design, limit arbitrary variants and verify the actual image dimensions and bytes. The image optimization guide explains the resource work that delivery proximity alone cannot solve.

Stale-response allowances also need a content decision. Reusing an older public article briefly is different from presenting outdated account permissions or transaction status. Do not copy a stale-serving rule from a static-content example onto sensitive endpoints. For those endpoints, freshness and authorization remain correctness requirements, not optional performance settings.

Run a small rollout with a clear rollback

Start with one public asset class, then one verified public HTML route if page caching is appropriate. Test a cold request, a repeated request, a changed document and an error. Use two independent browser sessions to confirm that private data never crosses users, and check that login and logout switch behavior correctly.

Record response headers with a GET request, using the real public URL in your environment.

bash
curl -sS -D - -o /dev/null https://example.com/news/

Inspect the documented cache-status field, Cache-Control, Age when present and the actual body. Compare with the origin through an authorized diagnostic path. A matching status header without matching content is not a successful test.

Keep the eligibility rules, invalidation procedure and rollback instructions together. Consult the server performance collection and the official CDN overview when extending the setup. Expand caching only when its measured benefit and update behavior are clear for the next content class.

Related guides