Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The image loading attribute depends only on the fetchpriority value #393

Merged

Conversation

cavaglieridomenico
Copy link
Contributor

What problem is this solving?

Currently resizing the images in the product-summary automatically sets the images to load lazy.

This behavior represents a performance issue especially in PLPs since the first product-summary image is usually the LCP element and if width and height are specified (obtaining the correct image size via CDN) the LCP element loads lazy (degrading LCP score).

The suggestion is to connect the loading value (without new props via CMS) to the fetchpriority value (which already has correct logic and props via CMS).

Furthermore, this feature removes the auto value that is not present in the possible loading attribute values (HTMLImageElement: loading property).

How to test it?

Workspace

Screenshots or example usage:

Production



Workspace

@cavaglieridomenico cavaglieridomenico requested review from a team as code owners July 15, 2024 16:31
@cavaglieridomenico cavaglieridomenico requested review from gvc, emersonlaurentino and vsseixaso and removed request for a team July 15, 2024 16:31
Copy link
Contributor

vtex-io-ci-cd bot commented Jul 15, 2024

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@vtex-io-docs-bot
Copy link

vtex-io-docs-bot bot commented Jul 15, 2024

Beep boop 🤖

I noticed you didn't make any changes at the docs/ folder

  • There's nothing new to document 🤔
  • I'll do it later 😞

In order to keep track, I'll create an issue if you decide now is not a good time

  • I just updated 🎉🎉

@iago1501 iago1501 requested review from iago1501 and vmourac-vtex and removed request for gvc and emersonlaurentino July 29, 2024 13:43
@iago1501
Copy link
Contributor

iago1501 commented Sep 10, 2024

Hi @cavaglieridomenico , first of all, thanks for the PR.

To accept that, we will have to discuss some points.

  • Do you have a page in itwhirlpool where it really affected the LCP in a positive way? I tried to check this behavior on certain pages but in none of them is the image the LCP. When not fetching the image, I understand that this image is removed from the SSR, so, in this case, this isn't the LCP anymore since Google is only worried at this point with the SSR, that's why I would like to check

  • Do you have the lighthouse/pagespeed metrics with this improvement? I'm thinking about why the shouldResize is a condition there, and it looks like this is related to the CLS of the page, when should resize, since it's in runtime, this might cause a layout shift.

  • Regarding removing the auto, this is correct

@cavaglieridomenico
Copy link
Contributor Author

cavaglieridomenico commented Sep 13, 2024

Hi @iago1501, thanks for your feedback and insight into the performance topic.

I usually work on many VTEX accounts (itwhirlpool, frwhirlpool, bauknecht, etc.).
Many PLPs contain a main banner image or a small banner image in the filter section which is the LCP element, instead of the first product-card image:
wpit-lcp-element

Otherwise many other PLPs do not contain any banner image and the first product-card image is the LCP element.
bkde-lcp-element

To analyze the second case we can use this URL as an example:
https://www.bauknecht.de/hausgeraete/waschen-trocknen/waschmaschinen
and here are related Lighthouse daily test reports for the last year.

Before 2024-07-30:
LCP element: first product-card image
product-card image fetchpriority: high
product-card image loading: lazy
product-card image size: 200x200 (prop via store)
bkde-lcp-element-waterfall-pre

After 2024-07-30:
LCP element: first product-card image
product-card image fetchpriority: high
product-card image loading: eager
product-card image size: 500xauto (default CDN size - I removed the size props from store to obtain loading eager)
bkde-lcp-element-waterfall-post

The aim of this PR is to achieve the possibility of managing the following cases:

Case of PLP without banner image
LCP element: first product-card image
product-card image fetchpriority: high
product-card image loading: eager
product-card image size: 200x200 (prop via store with no side effects on the loading type)

Case of PLP with banner image
LCP element: banner image
product-card image fetchpriority: low
product-card image loading: lazy
product-card image size: 200x200 (prop via store with no side effects on the loading type)

Case of product-card image on shelf
LCP element: Home/PDP/Editorial LCP element on the page
product-card image fetchpriority: low
product-card image loading: lazy
product-card image size: 200x200 (prop via store with no side effects on the loading type)

CLS in rendering product-card images is usually quite controlled using min-height rules.

@iago1501
Copy link
Contributor

iago1501 commented Sep 25, 2024

Hi @cavaglieridomenico , I will agree with this PR, mainly because auto doesn't exist, and lazy should be the correct behavior instead of auto. But, I only have some concerns about it. When I changed the way you did, I just found some important metrics running through lighthouse on devtools, here they go:

When adding loading lazy in elements above the fold, it triggered a warning regarding a delay in largest contentful paint, which makes sense. The LCP will always be the LCP no matter if it's loaded lazy or not. The way it makes more sense, it's using the prop that we have thinking about performance optimization in fetching priority, which is byPosition. This prop will give higher render priority for the first images (above the fold), giving high priority, the browser will have high priority when downloading (better TTFB). Check loading attribute, the recommendation is to only add it in images that are positioned below the fold:

https://www.w3schools.com/tags/att_img_loading.asp

image

image

When checking the delay in LCP, we can find these information:

image

The worst aggressor for the content is the TTFB for the assets, when checking load and render metrics, they are responsible for only 6% of the LCP, so, for a better metric on that, we should check for a better cache policy on the images maybe or something on the assets server.

But, I agree with you that the shouldResize doesn't look useful and there's no auto in loading attribute, but, keep in mind that this implementation might not affect your use case about an increase in LCP.

Another important references that might also be useful to understand:

https://web.dev/articles/lcp-lazy-loading?utm_source=lighthouse&utm_medium=devtools
https://web.dev/articles/optimize-lcp?utm_source=lighthouse&utm_medium=devtools#optimize_when_the_resource_is_discovered

Copy link
Contributor

@iago1501 iago1501 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR;

  • shouldResize doesn't look useful for not loading eager
  • loading attrib doesn't have auto
  • This might not reduce LCP of the page (check above evidences)

@iago1501 iago1501 merged commit 92cccb0 into vtex-apps:master Sep 25, 2024
4 of 5 checks passed
Copy link
Contributor

vtex-io-ci-cd bot commented Sep 25, 2024

Your PR has been merged! App is being published. 🚀
Version 2.90.0 → 2.90.1

After the publishing process has been completed (check #vtex-io-releases) and doing A/B tests with the new version, you can deploy your release by running:

vtex deploy [email protected]

After that your app will be updated on all accounts.

For more information on the deployment process check the docs. 📖

@iago1501 iago1501 added the bug Something isn't working label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants