CMS Development

jacjanowski
Member

Improve page loading time - Image is LCP

So my LCP for each blog post is my header <img>, which is loaded with 

<img  id="featured-image" fetchpriority="high" alt="{{content.featured_image_alt_text}}" src="{{ resize_image_url( content.featured_image,600 ) }}" width="570" height="358"/>

 I was sure to put 'fetchpriority="high"' as recommended, as well as preloading my CSS file as shown below: 

 

  <!-- Load the stylesheet that will reference the LCP image. -->
    <link rel="stylesheet" href="{{ get_asset_url('/Heartland_November2018 Theme/Coded Files/Heartland_November2018-style.css') }}">

    <!-- Preload the LCP image with a high fetchpriority so it starts loading with the stylesheet. -->
    <link rel="preload" fetchpriority="high" as="image" href="{{content.featured_image}}" type="image/webp">

 

After doing the SEO scan, I still get the error that my picture is the LCP and I need to find a way to reduce the time for it to load.

jacjanowski_0-1674235826467.png

 

How am I supposed to fix this? I've read the articles that Hubspot recommends me, as well as countless of other artciles and can't find a way to solve this. HELP PLEASE.

 

0 Upvotes
10 Replies 10
ellimccale
Participant

Improve page loading time - Image is LCP

Hi there! In addition to the article Jennifer linked (which is a fantastic resource), this one was just posted a few days ago with some additional tips:

 

https://www.smashingmagazine.com/2023/01/optimizing-image-element-lcp/

 

Check out the tips for `srcset` and `fetchpriority`. 🙂

 

Regardless of any optimizations, the largest image within the current viewport is the most likely candidate for LCP. The best we can do is make sure it's the right size and format for our users.

jacjanowski
Member

Improve page loading time - Image is LCP

Okay thanks for linking the articles. I have referenced the web.dev article a handful of times, but I'll take a look into the other one that was linked. I work tomorrow, so I will update tomorrow with what I come across. Thanks again, I'll be in touch.

0 Upvotes
jacjanowski
Member

Improve page loading time - Image is LCP

Following up: I just went ahead and tried it out. I referenced that article that was sent over, but I'm not sure if I have it written in correctly. Here it is

 

<img  id="featured-image" fetchpriority="high" alt="{{content.featured_image_alt_text}}" src="{{ resize_image_url( content.featured_image ) }}" srcset="{{ resize_image_url(content.featured_image, 0, 0, 480) }} 480w, {{ resize_image_url(content.featured_image, 0, 0, 800) }} 800w"
   sizes="(max-width: 600px) 480px,
       800px" width="570" height="358"/>

 

jacjanowski_0-1674405240601.png

 

 

The SEO hasn't changed.

0 Upvotes
jacjanowski
Member

Improve page loading time - Image is LCP

Furthermore, I have this in the <head> as mentioned on the article that was linked:

  <!-- Load the stylesheet that will reference the LCP image. -->
    <link rel="stylesheet" href="{{ get_asset_url('/Heartland_November2018 Theme/Coded Files/Heartland_November2018-style.css') }}"  crossorigin>

    <!-- Preload the LCP image with a high fetchpriority so it starts loading with the stylesheet. -->
    <link rel="preload" fetchpriority="high" as="image" href="{{content.featured_image}}" type="image/webp" crossorigin>

  

With this, I got a warning in my console. I don't think it's set up correctly. It's saying I set up my preload attribute, but it's not being used.

jacjanowski_0-1674579480454.png

 

0 Upvotes
Jnix284
Most Valuable Member | Elite Partner
Most Valuable Member | Elite Partner

Improve page loading time - Image is LCP

Thanks for sharing @ellimccale this is a great article, I've saved it to my list! 🙂


If my reply answered your question please mark it as a solution to make it easier for others to find.



Jennifer Nixon - Delivery Lead at Aptitude 8

connect with Jen on Linkedin

0 Upvotes
Jnix284
Most Valuable Member | Elite Partner
Most Valuable Member | Elite Partner

Improve page loading time - Image is LCP

Hi @jacjanowski  this is the best article I've found and refer to it every time I solve LCP issues.

 

You mentioned code related changes, have you already looked at optimizing the image files directly?


If my reply answered your question please mark it as a solution to make it easier for others to find.



Jennifer Nixon - Delivery Lead at Aptitude 8

connect with Jen on Linkedin

0 Upvotes
jacjanowski
Member

Improve page loading time - Image is LCP

So I converted my images into WebP, resized them to their appropriate dimensions so that they don't have to resize on page load, and compressed them as much as possible. I don't know what else to do besides that.

0 Upvotes
Jnix284
Most Valuable Member | Elite Partner
Most Valuable Member | Elite Partner

Improve page loading time - Image is LCP

@jacjanowski I looked at PageSpeed Insights to see if there was any more detail.

 

I think the only other thing you could do to improve it would be to load it as a background image or move it out of the viewport so it's not at the top of the page...


If my reply answered your question please mark it as a solution to make it easier for others to find.



Jennifer Nixon - Delivery Lead at Aptitude 8

connect with Jen on Linkedin

0 Upvotes
jacjanowski
Member

Improve page loading time - Image is LCP

I'll give this a shot. I will report back.

0 Upvotes
jacjanowski
Member

Improve page loading time - Image is LCP

So I gave it a try, and created a <div> that's the same height and width as the dimensions of the image that's rendered on the page. Here it is:

    #featured-image {
      background-image: url({{ content.featured_image }});
      height: 358px;
      width: 570px;
      float: left;
      margin-right: 30px;
    }


//HTML code
<div id="featured-image" ></div>

This code is creating a <div> that has the background image of the blog's featured image. The LCP remained the same as it was originally.

jacjanowski_1-1674260282402.png



I feel like this could be somewhat related as well, as it seems to be trying to use <script> tags that I turned off (or meant to).

jacjanowski_2-1674260404754.png

 

Lastly, this is what Google Lighthouse said; get scores on LCP and TBT, except these errors may have some signficance:

jacjanowski_3-1674260481914.png

 

Any further help would be greatly appreciated. Thanks ahaed of time!

 

0 Upvotes