use-the-astro-image-component
Installation
SKILL.md
Summary
Use Astro's built-in <Image /> component or the getImage() helper for local images. Avoid using standard HTML <img> tags for assets residing in src/.
Rationale
- Optimization: Automatically compresses and converts images (WebP/Avif).
- Layout Shift: Automatically interprets width/height to prevent Cumulative Layout Shift (CLS).
- Efficiency: Lazy-loading is enabled by default.
Guidance
- Import: Import the component
import { Image } from 'astro:assets';. - Local Assets: Import the image file directly
import myImg from '../assets/img.png';and pass it tosrc. - Remote Images: For remote images, use
inferSizeor explicitly provide dimensions.
Examples
Bad
<img src="/assets/hero.png" />