Caching & Performance

Optimization Strategies and Cache Management

Cache Behaviors

Cache behaviors define how CloudFront handles requests for different content types.

Path patterns: Define which requests match behavior
Origin selection: Route to appropriate origin server
Cache settings: TTL, headers, query strings

TTL Settings

Time To Live controls how long content stays cached at edge locations.

Default TTL

24 hours (86400 seconds)

Minimum TTL

0 seconds (no caching)

Maximum TTL

1 year (31536000 seconds)

Compression & Optimization

Gzip Compression

Automatically compress text-based files

  • • HTML, CSS, JavaScript files
  • • JSON and XML responses
  • • Up to 85% size reduction
  • • Faster download times

HTTP/2 Support

Modern protocol for better performance

  • • Multiplexing connections
  • • Header compression
  • • Server push capability
  • • Backward compatible

Origin Shield

Additional caching layer for origin protection

  • • Reduces origin load
  • • Improves cache hit ratio
  • • Better availability
  • • Cost optimization

Cache Control Headers

Origin Headers

// Cache for 1 hour
Cache-Control: max-age=3600
// No caching
Cache-Control: no-cache
// Expires header
Expires: Thu, 01 Dec 2024 16:00:00 GMT

CloudFront Behavior

Respect origin headers: Use Cache-Control from origin
Override with TTL: Force specific caching behavior
Customize by path: Different TTL per content type

Performance Best Practices

Static Content

Long TTL for images, CSS, JS files

Dynamic Content

Short TTL or no-cache for personalized content

Query Strings

Forward only necessary parameters

Headers

Minimize forwarded headers to origin

Caching & Performance Exam Tips

  • • Cache behaviors use path patterns to match requests
  • • Default TTL is 24 hours, can be overridden by origin headers
  • • Gzip compression reduces file sizes by up to 85%
  • • Origin Shield provides additional caching layer
  • • Use long TTL for static content, short TTL for dynamic content
Previous: CloudFront Fundamentals Next: Security & Access Control