How to Serve Images using S3
01 Jul 2025Amazon S3 is honestly a great choice for storing and serving static files like images. Pair it with CloudFront and boom — you’ve got a powerful, global CDN setup that’s fast and scalable. But… most people mess it up. Let’s fix that.
Store Smart, Not Just Fast
Just dumping images into S3 without thinking? Big mistake. Always store images in the formats and sizes you actually need. If you’re serving thumbnails — don’t upload a 4MB full-res photo. Compress it, reduce quality a bit, and save different sizes if your frontend needs it.
The Hidden Killer: No Caching Headers
This is the most ignored part. Without proper Cache-Control headers, your images are reloaded every time. That’s bad for performance and for cost.
Add this header:
Cache-Control: public, max-age=31536000
This tells the browser and CDN (like CloudFront or Cloudflare) to cache the image for 1 year. Fast loading, lower bandwidth, happy users.
TL;DR
- Store images in the sizes/quality you need.
- Compress thumbnails.
- Add caching headers.
- CloudFront + S3 = 🔥 (if used correctly)
Simple tweaks → big performance wins.