Media Platform: CDN Overhaul Saves $19K/Month, Cuts Latency 60%
A digital media company serving 8M monthly readers was paying $23,000/month in CDN costs and still seeing P95 page loads above 4 seconds in Southeast Asia and Africa. A 2-week infrastructure audit identified the root causes of both problems and fixed them simultaneously.
The Challenge
The company was using CloudFront for all assets with a single origin pull strategy. Images were not being resized for device type - a mobile user requesting a hero image received a 4MB file optimised for desktop. Static assets had no long-term caching headers, so CloudFront was fetching them from S3 on nearly every request. The result: high origin costs, high CDN costs, and slow load times in regions far from the US-East origin.
The Approach
We separated the content types: images (device-optimised, aggressively cached), static assets (immutable cache headers), and HTML (short TTL, edge-cached). We added CloudFront Functions for request-time image format negotiation and moved image resizing to Lambda@Edge on the first request.
The Implementation
Image optimisation pipeline
Lambda@Edge on viewer request detects device type and supported image formats (WebP/AVIF via Accept header). First-time requests trigger a Lambda that resizes and converts the image using Sharp, writes the result back to S3, and returns the optimised asset. Subsequent requests are served from CloudFront cache.
Cache header strategy
We added content-hash fingerprinting to all static assets (JS, CSS, fonts) and set Cache-Control: max-age=31536000, immutable. HTML responses got Cache-Control: s-maxage=60, stale-while-revalidate=300. CloudFront origin requests dropped 91% for static assets.
Multi-origin CloudFront distribution
We split the single CloudFront distribution into three: one for images (long TTL, Lambda@Edge), one for static assets (immutable cache), one for HTML (short TTL). This allowed cache policy tuning per content type and reduced unnecessary origin fetches across all three.
Regional edge caching expansion
We enabled CloudFront PriceClass_All to add edge locations in Southeast Asia, India, and Africa - previously not included in the PriceClass_100 configuration. The per-GB cost increase was offset 3× by the reduction in origin pulls.
Key Takeaways
- Serving desktop-sized images to mobile devices is often the single largest source of page performance problems and CDN cost
- Cache-Control: immutable on fingerprinted assets is the easiest single change to reduce CDN origin costs
- Splitting CDN distributions by content type unlocks cache policy tuning that is impossible with a single policy
- PriceClass_All is almost always cheaper in practice because edge caches reduce origin pull costs faster than the per-GB price increases
Facing Similar Challenges?
Book a free 30-minute audit and I will tell you what I see.