Prompt
I'm building a headless CMS site and need automatic image resizing
Latest observation
Nov 3, 2026
OpenAI APIWeb search: off
For a headless CMS site, the best approach is usually responsive images with automatic resizing via either:
-
An image CDN/service
Examples: Cloudinary, Imgix, ImageKit, Fastly Image Optimizer, Bunny Optimizer.
They let you request the same original image at different sizes/formats on the fly. -
Your own backend/image proxy Use a service or middleware like:
sharpfor Node.js- a CDN in front of your assets
- serverless functions for on-demand resizing
Recommended setup
If you want something low-maintenance, use an image CDN and store only the original in your CMS. Then generate URLs like:
?w=400?w=800?w=1200&format=webp
And serve them with:
srcsetsizes- modern formats like
WebPorAVIF
Example HTML
<img
src="https://cdn.example.com/image.jpg?w=800"
srcset="
https://cdn.example.com/image.jpg?w=400 400w,
https://cdn.example.com/image.jpg?w=800 800w,
https://cdn.example.com/image.jpg?w=1200 1200w
"
sizes="(max-width: 768px) 100vw, 50vw"
alt="Example"
/>
If you're using Next.js
Use next/image if possible. It handles resizing, optimization, and lazy loading automatically for supported sources.
Good practices
- Store original uploads in the CMS
- Resize on demand, not pre-generate every size
- Use
srcsetfor responsive layouts - Convert to WebP/AVIF when supported
- Cache aggressively at the CDN edge
If you want, I can recommend the best option based on your stack:
- Next.js
- Nuxt
- Gatsby
- custom React/Vue
- plain HTML
- specific CMS like Contentful, Strapi, Sanity, or WordPress