I am trying to optimise a 2.4 MB image (4514x5789) with Astro.
I tried:
<Image
src={Image}
alt="image"
quality={80}
format="webp"
loading="lazy"
widths={[390, Image.width]}
sizes={`(max-width: 768) 390px, ${Image.width}px`}
class="rounded-lg"
/>
Unfortunately this is not enough according to PageSpeed Insights. What can I change to get a performance score of 100?
According to the Astro docs, the
widthsattribute you're providing will be used to generate thesrcsetin HTML.Here's what that looks like on your page:
It seems the problem is that you're passing the width of the original image as one of the potential sizes for the
srcset. On devices smaller than 768px, the 390px version of the image will be used. On devices wider than 768px, the full 4514px image will be used instead.It also seems that the largest the image could actually render on the page is 390px, so you don't need any sources larger than that. To fix the issue, try removing
Image.widthfromwidthsandsizes: