Astro image optimization guide
How to use Astro assets, responsive layouts, and remote image rules without bloating static builds.
Astro gives you strong asset tooling, but static sites still suffer when image generation is unconstrained. The right page explains what belongs in build-time transforms and what should stay on a CDN.
Best for
Content-heavy static or hybrid Astro sites
Default goal
Build-time control with predictable responsive output
Watch closely
Remote image handling and build cost
Recommended setup
Use Astro assets for local editorial media and document when remote or CMS images should bypass local processing. Static sites often become slow to build because every remote image starts doing local work.
- Use imported local assets for images you publish and control.
- Keep remote-domain rules specific and explicit.
- Move highly dynamic or third-party media to a CDN-backed workflow instead of forcing everything through the build.
Responsive Astro image
---
import { Image } from 'astro:assets'
import hero from '../assets/hero.jpg'
---
<Image
src={hero}
alt="Editorial hero"
widths={[480, 768, 1200]}
sizes="(min-width: 1024px) 1200px, 100vw"
formats={['avif', 'webp']}
/>What to measure
- Build time and asset-generation volume after adding responsive widths.
- Byte savings between source assets and delivered formats.
- How many templates still fall back to raw `<img>` tags without sizing rules.
Where Astro-specific value comes from
Searchers looking for Astro image optimization usually want a boundary: what Astro should optimize locally, what the CDN should handle, and how to keep builds sane.
Checklist
- Use imported assets for local images.
- Set width ladders per layout, not globally by habit.
- Keep remote image domains restricted.
- Avoid expensive build-time transforms for volatile content.
Common mistakes
- Generating too many width variants for every image.
- Running remote media through the build when a CDN would be more stable.
- Ignoring aspect ratios and relying on CSS alone to fix layout.
Quick answers
When should Astro handle image optimization locally?
When the media is part of your repo or a stable content workflow and the output is predictable enough to justify build-time processing.
What usually makes Astro image builds slow?
Too many generated widths, too many formats, or trying to process large remote image inventories during static builds.
Related pages
Framework Guide
Next.js image optimization guide
How to ship responsive images in Next.js with sane remote patterns, right-sized assets, and predictable LCP behavior.
Framework Guide
Eleventy image optimization guide
How to use Eleventy Image for responsive output, controlled widths, and manageable build performance in static publishing workflows.
Reference
Hero image size guide for websites
How large hero images should be before responsive resizing, and how to avoid giant full-bleed assets that slow the page down.
From the archive
Understanding Image Resizing: Basics and Benefits
Boost site speed & SEO with top image resizing & optimization tools: master JPEG, PNG, WebP compression, automation, quality tips, audits & metrics.
Decoding the Pixels: The Ultimate Guide to Ideal Image Dimensions for Web and Mobile (2025 Update)
Find ideal image dimensions for web & mobile. Master responsive techniques & optimization (WebP/AVIF) for sharp, fast visuals on all devices.
How to Use a CDN for Responsive Images Across All Devices
Learn how to effectively use a CDN to deliver responsive images across devices, enhancing site performance, user experience, and SEO visibility.