how can i fix largest contentful paint issue in next js image

752 views Asked by At
 <div className={styles.imageContainer}>
                  <Image
                    src="https://res.cloudinary.com/di7j408eq/image/upload/v1685516535/outdoor-living-slider_1_nsnsnr.webp"
                    width={500}
                    height={500}
                    alt="calgary landscaping"  
                    quality={100}  
                    priority            
                  />
                </div>

TTFB 6% 480 ms Load Delay 0% 0 ms Load Time 10% 760 ms Render Delay 83%

1

There are 1 answers

0
maulik On

To improve Image output: Use "Picture" tag

<picture>
  <source media="(max-width:699px)" srcSet="https://res.cloudinary.com/di7j408eq/image/upload/v1685516535/outdoor-living-slider_1_nsnsnr.webp" type="image/webp" /> // for tab media size
  <source media="(max-width:640px)" srcSet="https://res.cloudinary.com/di7j408eq/image/upload/v1685516535/outdoor-living-slider_1_nsnsnr.webp" type="image/webp" /> // for mobile media size
  <Image
    src="https://res.cloudinary.com/di7j408eq/image/upload/v1685516535/outdoor-living-slider_1_nsnsnr.webp"
    width={500}
    height={500}
    alt="calgary landscaping"
    quality={100}
    priority="low"
    loading="lazy"
  />
</picture>

Keep priority="low" & loading="lazy".

If the image is from the first fold then keep its priority="high" & loading="eager".

Must use webp images and if you have SVG then add package 'react-svg' and use it for batter output.

Also suggested using the Next.js dynamic import if yet not used. Ref: https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#nextdynamic