Intermediate · 7 lessons

CDN

A Content Delivery Network (CDN) distributes copies of your website across servers worldwide. Users connect to the nearest edge location instead of your origin server — reducing latency, saving bandwidth, and absorbing traffic spikes.

Key Concepts

Edge Servers Origin Server Cache Hit Ratio Anycast Routing SSL at Edge Cache Purging Cloudflare / AWS CloudFront DDoS Protection

Key Takeaways

  • ✓ CDN reduces latency by serving content from nearby edge servers.
  • ✓ Cache static assets (CSS, JS, images) at CDN; dynamic content hits origin.
  • ✓ Cloudflare free tier includes CDN, SSL, and basic DDoS protection.
  • ✓ Purge CDN cache after every deployment to show fresh content.

Lessons in This Topic

1

How CDNs Work

Edge caching and origin pull explained.

First request: CDN edge fetches from origin, caches copy, delivers to user. Subsequent requests: served from edge cache (cache HIT). Cache MISS fetches from origin again. TTL determines how long content stays cached. 200+ edge locations vs 1 origin server.
2

Setting Up Cloudflare CDN

Free CDN with SSL and security.

Add domain to Cloudflare, update nameservers. Orange-cloud (proxied) records route through CDN. Enable "Always Use HTTPS". Configure caching rules by file type. Enable Brotli compression. Use Page Rules for custom cache behavior. Free tier handles most small-medium sites.
3

CDN Cache Rules & TTL

Control what gets cached and for how long.

Static assets (/css/, /js/, /images/): cache 1 year with versioning. HTML pages: short TTL (1 hour) or bypass cache. API endpoints: never cache. Use Cache-Control headers from origin. CDN respects origin headers unless overridden by CDN rules.
4

CDN for WordPress

Integrate CDN with WP caching plugins.

Install Cloudflare plugin or CDN Enabler. Set correct site URL. Exclude admin, cart, and logged-in pages from cache. Purge cache on post publish. Use CDN URL for wp-content/uploads. Combine with page cache plugin for maximum performance.
5

CDN Security Benefits

DDoS protection and WAF at the edge.

CDN absorbs Layer 3/4 DDoS attacks before reaching origin. WAF blocks SQL injection, XSS at edge. Hide origin IP to prevent direct attacks. Rate limiting per IP. Bot management filters bad bots. All included in Cloudflare free/pro plans.

Related Topics

Ask AI