Architecture Beginner
CDN Configuration — Content Closer to the User¶
CDNCloudFrontPerformance 3 min read
CDN configuration for web applications. CloudFront, Cloudflare, cache headers.
What Is a CDN?¶
A Content Delivery Network distributes static content to edge servers around the world. Users download from the nearest server.
Cache Headers¶
# Immutable assets (with hash)
Cache-Control: public, max-age=31536000, immutable
# HTML (always revalidate)
Cache-Control: no-cache
# API responses
Cache-Control: private, max-age=60
CloudFront + S3¶
resource "aws_cloudfront_distribution" "cdn" {
origin {
domain_name = aws_s3_bucket.static.bucket_regional_domain_name
origin_id = "S3-static"
}
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
viewer_protocol_policy = "redirect-to-https"
compress = true
default_ttl = 86400
}
}
Summary¶
CDN is low-hanging fruit for performance. Proper cache headers + content hashing = dramatic improvement.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.