vtex-apps / product-summary

VTEX Product Summary app
11 stars 52 forks source link

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

Open cavaglieridomenico opened 2 months ago

cavaglieridomenico commented 2 months ago

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

vtex-io-ci-cd[bot] commented 2 months ago

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:

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

vtex-io-docs-bot[bot] commented 2 months ago

Beep boop :robot:

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

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

iago1501 commented 1 week ago

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

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

cavaglieridomenico commented 1 week ago

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.