Skip to main content

CDN Foundation

A Content Delivery Network (CDN) like Cloudflare sits between your users and your origin server, caching your website's static assets and HTML at edge locations around the world. By serving content from a data center physically closer to the visitor, a CDN dramatically reduces latency, protects your server from traffic spikes, and is essential for achieving a fast Time to First Byte (TTFB) globally.

CDN vs Other Cache Layers

LayerScopeBenefitLimitation
Server Cache (LSCache)HTML stored on origin serverFast for local originDoesn't reduce global latency
Browser CacheAssets stored on deviceZero network on repeat visitsFirst visit always needs download
Object Cache (Redis)DB queries stored in memorySpeeds logged-in/dynamic viewsNo impact on geographic latency
CDN (Cloudflare)HTML + assets cached at edge PoPsCuts latency, protects, global deliveryMust exclude dynamic/cart pages

How Cloudflare Improves Delivery

FeatureWhat It DoesWhy It MattersTypical Impact
Edge HTML Caching (APO)Serves full pages from PoPsReduces global TTFBTTFB 0.6–1.0s globally
Tiered CacheUpper-tier PoPs share cache with lower-tierImproves cache hit-rate, reduces origin pullsPSI +5–10
Brotli CompressionCompresses assets at edgeFaster transfer, smaller payloadFCP/LCP 0.1–0.3s
Early HintsSends preload hints while origin still processesFaster renderingLCP 0.1–0.2s
Anycast DNSRoutes to nearest PoP automaticallyFaster DNS resolutionDNS 20–50ms
WAF/Rate LimitingFilters malicious trafficStability + uptimePrevents downtime

Performance Benefits in Numbers

MetricWithout CloudflareWith CloudflareGain
Global TTFB (Asia→US origin)1.2–1.6s0.3–0.5s0.9–1.1s
Global LCP2.8–3.5s1.9–2.4s0.9–1.1s
PSI Mobile65–7580–90+15–20 points
DNS Resolution60–120ms20–50ms40–70ms

Static vs Dynamic Strategy

Strategy: Aggressive Cloudflare edge caching (APO ON, long TTL).

Why: Safe to serve prebuilt HTML; content rarely changes, yielding the highest performance gains.

Best Practices

  1. Always use Cloudflare DNS + Proxy (orange cloud).
  2. Enable APO for HTML caching.
  3. Combine with LSCache at origin — LSCache = HTML source, Cloudflare = global delivery.
  4. Exclude cart/checkout/account routes from edge cache.
  5. Turn on Tiered Cache for global consistency.
  6. Always test after enabling features — avoid broken logins or carts.

Verification Steps

Check via curl

check-cdn-headers.sh
curl -I https://example.com/

Expected Output:

cdn-headers-output
cf-cache-status: HIT
cf-ray: <id>

Check DNS resolution speed

check-dns-resolution.sh
dig example.com | grep "Query time"

Expected Output:

dns-resolution-output
;; Query time: 20 msec

Quick Lab

Lab Instructions
  1. Point DNS to Cloudflare — wait for propagation.
  2. Enable orange cloud proxy.
  3. Enable APO + Brotli + Tiered Cache.
  4. Visit site from 2 regions (US + Asia).
  5. Run curl -I to confirm cf-cache-status: HIT.
  6. Run Lighthouse — compare TTFB/LCP before vs after.

Cheat Sheet (Foundation Cloudflare CDN)

View Cheat Sheet
TaskSetting
DNSCloudflare Anycast DNS
ProxyOrange Cloud = ON
HTML CacheAPO ON
Asset CacheAuto, Brotli ON
Global DeliveryTiered Cache ON
Exclusions/cart/, /checkout/, /my-account/
Verifycf-cache-status: HIT
SecurityWAF + Rate Limiting ON
Summary

With Cloudflare in place, expect global TTFB < 500ms and Core Web Vitals score improvements across mobile and desktop.

What's Next