0
0
Astroframework~20 mins

Image optimization with astro:assets - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Astro Image Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Astro optimize images using 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?

Astro
import img from '../assets/photo.jpg';

---

<img src={img} alt="Sample photo" />
AThe image is converted to a base64 string and embedded directly in the HTML.
BThe image is loaded as-is without any optimization or resizing.
CThe image is automatically resized and optimized for the device's screen size and format.
DThe image is replaced with a placeholder and loaded lazily only on scroll.
Attempts:
2 left
💡 Hint

Think about what astro:assets does to images during build time.

📝 Syntax
intermediate
1:30remaining
Which import syntax correctly uses astro:assets for image optimization?

Choose the correct way to import an image for optimization in an Astro component.

Aimport photo from '../assets/photo.jpg';
Bimport photo from 'astro:assets/photo.jpg'; // with curly braces
Cimport photo from 'astro:assets';
Dimport photo from 'astro:assets/photo.jpg';
Attempts:
2 left
💡 Hint

Remember how relative paths and astro:assets work together.

🔧 Debug
advanced
2:00remaining
Why does this Astro image import cause a build error?

Given this code snippet, why does the build fail?

Astro
import img from 'astro:assets/photo.png';

---

<img src={img} alt="Example" />
AThe path 'astro:assets/photo.png' is invalid; images must be imported using relative paths.
BThe image file format PNG is not supported by Astro's image optimizer.
CThe <code>img</code> variable is not used correctly in the JSX syntax.
DAstro requires images to be imported with curly braces around the path.
Attempts:
2 left
💡 Hint

Check how image paths are resolved in Astro imports.

state_output
advanced
2:30remaining
What is the output HTML of this Astro image component using astro:assets?

Given this Astro component code, what does the rendered HTML look like?

Astro
---
import photo from '../assets/photo.jpg';
---

<img src={photo.src} alt="Photo" width={photo.width} height={photo.height} loading="lazy" />
A<img src="../assets/photo.jpg" alt="Photo" loading="lazy">
B<img src="/assets/photo.abc123.jpg" alt="Photo" width="800" height="600" loading="lazy">
C<img src="data:image/jpeg;base64,..." alt="Photo" width="800" height="600">
D<img alt="Photo" width="800" height="600" loading="lazy">
Attempts:
2 left
💡 Hint

Astro generates optimized image URLs with hashes and includes dimensions.

🧠 Conceptual
expert
3:00remaining
Why is using 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.

AIt requires manual configuration for each image size and format to optimize properly.
BIt converts all images to PNG format to ensure maximum quality regardless of file size.
CIt disables image caching to always load the latest image version from the server.
DIt automatically generates multiple optimized versions and serves the best one based on device and browser, reducing manual work and improving performance.
Attempts:
2 left
💡 Hint

Think about automation and performance benefits.