The average response time for a request that travels from New York to a London origin server is 74 milliseconds. Serve that same asset from a PoP in New Jersey, and the number drops to roughly 19 milliseconds. That’s not a theoretical improvement — it’s the kind of reduction in network latency for a single round trip that can turn several hundred milliseconds into well under a hundred. Yet most first-time CDN setups never capture that gain, because the person configuring the CDN stops at the moment the dashboard shows “Active” and moves on.

The problem isn’t the CDN. The problem is that the default configuration is a starting point, not a finished state. A CDN that caches nothing, or caches the wrong things, or serves stale content from the wrong cache key, will measurably underperform. This guide covers the full path: choosing the right configuration, making the DNS cutover, setting cache behavior that matches your asset types, and verifying — with real numbers — that the CDN is doing what you think it’s doing.

Myth vs. Reality: The CDN Setup Checklist

MythReality
“Click ‘Add DNS Record’ and you’re done.”The DNS record is the beginning. Cache rules, cache keys, and origin shields determine the outcome.
“TTL of 1 year is best for everything.”A long TTL on HTML that changes daily serves stale pages. TTL must match content volatility.
“A CDN is a single switch.”A CDN is a chain: DNS → edge → cache → origin. Each link can fail independently.
“If the CDN is up, performance improved.”You need before/after measurements. Without a baseline, you’re guessing.
“More edge nodes always help.”For small sites, the origin’s distance to the closest PoP matters more than the total PoP count.

Each row in that table maps to a decision you’ll make in the steps below. Ignore any one of them, and the CDN will still deliver some assets faster — but the overall user experience won’t match what the architecture is capable of.

Step 1: Choose Your CDN Provider and PoP Strategy

You have three realistic options: a standalone CDN (Cloudflare, Fastly, KeyCDN, Bunny.net), a cloud-native CDN (AWS CloudFront, Azure Front Door), or a CDN bundled with your hosting platform. For a first deployment, a standalone provider with a free or low-cost tier is the pragmatic choice, because it lets you experiment without committing to cloud infrastructure complexity.

The key decision isn’t the vendor — it’s the PoP (Point of Presence) geography. Check the provider’s network map before you sign up. If your users are concentrated in Brazil, a provider with 300 PoPs mostly in North America won’t help much. The relevant metric is: what’s the distance from your users to the nearest PoP, and from that PoP to your origin? Each hop adds 1–2 ms of propagation delay for every 100–200 km.

For most early-stage sites, a single origin behind the CDN is sufficient. Only add multiple origins after you’ve confirmed the CDN is working and you’re hitting origin resource limits.

Step 2: Create Your CDN Resource and Configure the Origin

In every CDN, you’ll create a “resource” or “distribution” that points to your origin server. The configuration block below is the CloudFront equivalent, but the same fields exist across providers:

# Example AWS CLI command to create a CloudFront distribution
# Replace the OriginId, DomainName, and DefaultRootObject values

aws cloudfront create-distribution \
  --origin-domain-name origin.example.com \
  --default-root-object index.html \
  --default-cache-behavior '{
      "TargetOriginId": "my-origin",
      "ViewerProtocolPolicy": "redirect-to-https",
      "MinTTL": 0,
      "MaxTTL": 31536000,
      "DefaultTTL": 86400,
      "ForwardedValues": {
        "QueryString": false,
        "Headers": ["Origin", "Access-Control-Request-Headers", "Access-Control-Request-Method"]
      }
    }' \
  --aliases '{"Quantity": 1, "Items": ["cdn.example.com"]}'

Three fields in that command matter more than the rest:

  1. DefaultTTL: 86400 — this is the fallback cache duration when your origin doesn’t send Cache-Control headers. 24 hours is a reasonable starting point, but you’ll adjust it per asset type in Step 4.
  2. ForwardedValues — you want to forward Origin and CORS-preflight headers if you serve fonts or API responses. Forwarding all cookies or query strings will severely reduce your cache hit rate.
  3. ViewerProtocolPolicy — always redirect to HTTPS. HTTP requests to a CDN edge are both a security risk and a performance risk, since secure contexts get priority in browsers.

Before you make the DNS cutover, point a test hostname at the CDN and verify the origin connection works. Use curl to simulate an edge request:

curl -I https://your-cdn-endpoint.net/assets/logo.png
# Expect: HTTP/2 200, x-cache: Hit from cloudfront, via headers

If you see 502 Bad Gateway or the origin’s IP in the Via header, your origin configuration is wrong. Fix it before touching production DNS.

Step 3: The DNS Cutover — and the 15-Minute Failure Window

This is where most setups go wrong. You’ll point cdn.yourdomain.com at the CDN provider via a CNAME record. The provider gives you a target hostname (e.g., d1234.cloudfront.net). Create the CNAME:

# In your DNS provider's control panel, add:
# Type: CNAME
# Name: cdn
# Value: d1234.cloudfront.net
# TTL: 300 seconds (5 minutes)

The failure window: after you change the DNS record, the old record might still be cached by resolvers. If you had a DNS entry pointing cdn.yourdomain.com to an A record with your server’s IP, you’ll have mixed traffic for up to the old TTL’s duration. This causes intermittent 502s as some requests hit the CDN edge and others hit your origin directly with an incorrect Host header.

Mitigation: Keep the old A record for 24 hours after the cutover, pointing to the origin explicitly. Alternatively, do the cutover during a low-traffic window. In practice, this avoids the worst symptoms.

Verification: After 5–15 minutes, run this from a machine outside your local network:

dig +short cdn.yourdomain.com
# Should return one of the CDN provider's IP addresses

Also verify the CDN is serving content, not acting as a passthrough:

curl -sI https://cdn.yourdomain.com/styles/main.css | grep -i "x-cache\|age\|via"

If the response includes x-cache: Miss from cloudfront, the edge didn’t have the asset and fetched from origin. That’s expected on the first request. Repeat the same request a second time — you should see x-cache: Hit and an Age header greater than 0.

Step 4: Cache Configuration — Match TTL to Content Type

This is the step that separates a working CDN from a performing CDN. The default TTL of 24 hours caches everything identically, which is wrong for a typical site.

Apply this pattern on your origin server — sending Cache-Control headers is the preferred way to control CDN behavior, rather than relying on CDN-side overrides:

# nginx example — origin server configuration

# Static assets: immutable, long TTL
location ~* \.(?:css|js|png|jpg|jpeg|gif|webp|svg|woff2?)$ {
    add_header Cache-Control "public, max-age=31536000, immutable";
}

# HTML: short TTL, must revalidate
location = /index.html {
    add_header Cache-Control "public, max-age=300, must-revalidate";
}

# API responses: no CDN caching unless you have explicit versioned URLs
location /api/ {
    add_header Cache-Control "no-store";
}

The trade-off: a 1-year TTL on main.js means the browser and the CDN will cache it aggressively. If you change that file, users on the old version will see stale JavaScript until the URL changes. The solution is cache-busting via filenames: main.a1b2c3.js instead of main.js. Every time the file changes, the filename changes, so the old entry expires naturally and the new one gets fetched.

For HTML, never use a TTL longer than 5–10 minutes unless you’re serving a static site that you fully control. The moment you deploy a new version of your index page, you want the CDN to revalidate within minutes, not hours.

When NOT to use a long TTL: any page that includes a logged-in user’s name, a shopping cart count, or any personalized content. For those, set Cache-Control: no-store or use the CDN’s built-in “bypass cache for cookie” option. Caching personalized content is how users see other users’ data — a failure mode that’s both embarrassing and potentially a legal liability.

Step 5: Cache Keys — The Silent Performance Killer

The cache key is the identifier the CDN uses to decide whether a request hits or misses. The default key is the full URL. That sounds fine — until you realize the URL includes query strings that don’t affect the content.

Consider an image URL: /images/product.jpg?v=123. If your code appends a version query string on every render, the CDN sees /images/product.jpg?v=124 as a different object. You get zero cache hits, and the CDN fetches from origin on every request.

Fix: Configure the CDN to ignore query strings for static assets. In CloudFront, set QueryString: false in the forwarded values. In Cloudflare, enable “Ignore query string” in a Cache Rule.

But you also need to forward some query strings when they change the response — e.g., language selection (?lang=fr). The rule: forward only the query params that your origin uses to generate different content.

The failure mode: if you forward all query params, cache hit rate collapses. If you forward none while your origin serves different content per param, users see stale or wrong content. In practice, start by ignoring all query strings, then add exceptions only for parameters that measurably change the response body.

Verification with cache hit ratio:

# CloudFront — enable "CacheHitRatio" in CloudWatch Metrics
# Then query after 1 hour of production traffic:
# Target: CacheHitRatio > 90%
# If it's below 80%, your cache key is likely too strict, or your TTLs are too short.

Step 6: Verify the End-to-End Result

The final step is measurement. A CDN without a baseline is a guess. Run this test sequence before the cutover and again 24 hours after:

# Before CDN (direct to origin):
curl -s -o /dev/null -w "Origin Time: %{time_total}s\n" https://origin.example.com/styles/main.css

# After CDN (once cache is warm — run the request twice):
curl -s -o /dev/null -w "CDN Cold: %{time_total}s\n" https://cdn.example.com/styles/main.css
curl -s -o /dev/null -w "CDN Warm: %{time_total}s\n" https://cdn.example.com/styles/main.css

# Compare:
# Origin Time: 0.120s
# CDN Cold:    0.045s
# CDN Warm:    0.012s

A warm-cache response under 20 ms is the goal. If your warm time is above 50 ms, one of three things is wrong: the CDN edge is farther from the user than expected, the cache key is causing misses, or the origin is being contacted anyway because of an overly strict cache rule.

Run a few page-load tests from multiple geographic locations (webpagetest.org, or the CDN provider’s own testing tool). The metric to watch is TTFB (Time to First Byte) — it should drop from your origin baseline by at least 50% for cached assets. That drop directly moves First Contentful Paint, which is a Core Web Vital.

When a CDN Is the Wrong Answer

A CDN won’t fix a slow backend. If your origin takes 2 seconds to generate a response — due to database queries, slow server-side rendering, or an overloaded process — the CDN can only mask that for content it’s allowed to cache. For dynamic, uncacheable pages, the CDN adds a network hop that increases latency by 1–3 ms compared to direct origin access.

Signs that a CDN is hurting rather than helping:

  • Your pages are mostly personalized (logged-in dashboards, user feeds) and you’re setting no-store on everything. The CDN becomes a pass-through with extra overhead.
  • Your origin is in the same region as your users, and the nearest CDN PoP is on another continent. The detour adds more time than it saves.
  • Your cache hit ratio stays below 60% after 48 hours. You’re paying for infrastructure that’s doing nothing.

In those cases, the better investment is origin-side optimization: a faster web server (nginx over Apache), higher PHP memory limits, or a read replica for the database database.

Your Last Step

After you’ve configured the CDN, run the cache-hit-ratio report for one full day. A healthy static-asset setup sits above 95%. If it doesn’t, audit the cache key first, then the TTLs.

The 74% latency reduction is real, but it only appears when the cache is warm, the keys are clean, and the TTLs match the content. Your dashboard said “Active” minutes after the DNS record propagated. The performance you promised your users — that takes another afternoon of configuration, verification, and tweaking. That’s the difference between installing a CDN and operating one.

Related guides: How to Set Up a CDN for Beginners: A Step-by-Step Performance Guide, Caching Strategies for Beginners: A Step-by-Step Guide to Faster Page Loads, and Troubleshooting Why Your CDN Isn’t Improving Page Speed: Common Mistakes.