Performance: Image optimization
Image optimization affects page load speed and visual stability by reducing image file sizes and controlling how images load and render.
export default function Page() {
return <img src="/images/photo-optimized.jpg" alt="Photo" width={600} height={400} />;
}export default function Page() {
return <img src="/images/large-photo.jpg" alt="Photo" />;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large unoptimized image without dimensions | Minimal | Multiple reflows on image load | High paint cost due to large decode | [X] Bad |
| Optimized image with width and height set | Minimal | Single layout pass | Lower paint cost with smaller decode | [OK] Good |
Image component for images on your website?Image component automatically optimizes images for better performance.Image component in your React component?Image component is imported from '@remix-run/react' using named import.src and alt props, not source or altText.import { Image } from '@remix-run/react';
export default function Photo() {
return (
<Image src='/cat.png' alt='Cute cat' width={400} height={300} loading='lazy' />
);
}import { Image } from '@remix-run/react';
export default function Logo() {
return <Image source='/logo.svg' alt='Logo' />;
}Image component expects src, not source.source='/logo.svg' to src='/logo.svg' to display the image.loading='lazy' delays image loading until needed, speeding page load.Pass the test and this pattern moves unknown