What is a CDN?
A Content Delivery Network distributes your static assets (images, CSS, JS) across servers worldwide. Visitors load files from the nearest server, dramatically reducing latency.
How CDNs Work
- You configure your CDN to pull content from your origin server
- When a visitor requests a file, the CDN serves it from the nearest edge location
- If the edge doesn't have the file (cache miss), it fetches from your origin and caches it
Popular Free CDN Options
- Cloudflare — free tier includes CDN, DNS, basic DDoS protection, and SSL
- BunnyCDN — pay-as-you-go starting at $0.01/GB
Setting Up Cloudflare
- Sign up and add your domain
- Point your nameservers to Cloudflare
- Enable "Proxied" mode on your DNS records (orange cloud icon)
- Configure caching rules under Caching → Configuration
Cache Headers for CDN
# Nginx — set proper cache headers
location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
add_header Vary "Accept-Encoding";
}Measuring Impact
Test your site speed before and after CDN setup using:
- Google PageSpeed Insights
- GTmetrix
- WebPageTest