How to set up a CDN for a static website
· Category: Cloud & Networking
Short answer
Create a CDN distribution pointing to your static origin (S3 bucket, VPS, or object store), configure SSL/TLS, set cache behaviors by file extension, and point your DNS to the CDN endpoint.
Details
Most providers (Cloudflare, AWS CloudFront, Fastly) let you define origin pull behavior and TTLs. For a static site, cache HTML for a short TTL (minutes) and assets like CSS, JS, and images for weeks or months with immutable filenames. Proper DNS configuration is essential: create a CNAME or ALIAS record from your domain to the CDN hostname and validate ownership for SSL provisioning. CDNs speed up content delivery by terminating connections closer to users and compressing responses. Enabling HTTP/2 or HTTP/3 and Brotli compression further improves Core Web Vitals by reducing transfer sizes.
Tips
- Use cache-busting query strings or hashed filenames to avoid serving stale assets.
- Enable origin shield or tiered caching if your origin has strict rate limits.
- Test cache hit ratios with browser dev tools or CDN analytics before going live.