astro:assets?Consider an Astro component importing an image with import img from 'astro:assets'. What happens when this image is used in the component?
import img from '../assets/photo.jpg'; --- <img src={img} alt="Sample photo" />
Think about what astro:assets does to images during build time.
Astro's astro:assets automatically optimizes images by resizing and converting them to modern formats based on device needs, improving performance.
astro:assets for image optimization?Choose the correct way to import an image for optimization in an Astro component.
Remember how relative paths and astro:assets work together.
You import images from your local assets folder using a relative path, and Astro processes them via the astro:assets integration automatically.
Given this code snippet, why does the build fail?
import img from 'astro:assets/photo.png'; --- <img src={img} alt="Example" />
Check how image paths are resolved in Astro imports.
Astro expects image imports to use relative paths to local files. Using 'astro:assets/photo.png' as a path is invalid and causes a build error.
astro:assets?Given this Astro component code, what does the rendered HTML look like?
--- import photo from '../assets/photo.jpg'; --- <img src={photo.src} alt="Photo" width={photo.width} height={photo.height} loading="lazy" />
Astro generates optimized image URLs with hashes and includes dimensions.
Astro's astro:assets provides an object with src, width, and height. The src is a hashed URL for caching and optimization.
astro:assets better than manually optimizing images for a website?Choose the best reason why astro:assets image optimization is preferred over manual image resizing and format conversion.
Think about automation and performance benefits.
astro:assets automates creating multiple image sizes and formats, then serves the best one for the user's device, saving time and improving load speed.