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

Performance 2024: image prioritization and discoverability #3960

Merged
merged 8 commits into from
Dec 10, 2024
Merged

Conversation

rviscomi
Copy link
Member

@rviscomi rviscomi commented Dec 5, 2024

Updates the prioritization and discoverability queries and includes their results in the chapter, also adds a figure for % of unsized images

I did a bit of editorializing so definitely want @ines-akrap and @imeugenia's LGTM

Once published, I'll update the corresponding links in https://web.dev/articles/top-cwv to point to the 2024 results

@rviscomi rviscomi marked this pull request as ready for review December 10, 2024 00:40
@rviscomi rviscomi requested a review from tunetheweb December 10, 2024 00:40

Overall, lazy-loading images is a helpful performance technique that should be used to postpone loading of non-critical resources until they are near the viewport. However, using lazy-loading on the LCP image will delay the browser from loading it quickly. That is why lazy-loading should not be used on LCP elements. In this section, we explore how many sites use this performance anti-pattern.
As we'll explore in the following sections, there are three primary ways that websites prevent their LCP resources from being statically discoverable: lazy-loading, CSS background images, and client-side rendering.
Copy link
Contributor

@kevinfarrugia kevinfarrugia Dec 10, 2024

Choose a reason for hiding this comment

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

If an LCP image is lazy loaded (natively) then it is still statically discoverable. Only custom approaches (6.7% of sites) are included in the 35%. Might be worth clarifying.

Copy link
Member

Choose a reason for hiding this comment

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

If an LCP image is lazy loaded (natively) then it is still statically discoverable

Effectively not. It's not discoverable by the preload scanner, and needs CSS to run layout to know if it's in viewport. Which effectively means it's not statically discoverable (i.e. it's the same as if it was hidden in CSS background image, or within JS that needs to run).

Copy link
Contributor

@kevinfarrugia kevinfarrugia Dec 10, 2024

Choose a reason for hiding this comment

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

Fair enough, but the custom metric definition of is_statically_discoverable doesn't take this into consideration.

The image is considered statically discoverable if it is preloaded or available in the image src or srcset:

      const rawLcpElement = Array.from(rawDoc.querySelectorAll('picture source, img, svg image')).find(i => {
        let src = i.src;
        if (i.hasAttribute('srcset')) {
            src = splitSrcSet(i.srcset).find(src => src == lcpUrl);
        } else if (i.hasAttribute('href')) {
            src = i.getAttribute('href');
        }

        return new URL(src, location.href).href == lcpUrl;
    });

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point @kevinfarrugia, I think it's at least worth mentioning that native lazy loading isn't included in the static discoverability stat. We might want to consider looking at a different high-level metric in the future that captures all of the causes of resource load delay.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated PTAL

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

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

LGTM but would like at least one author to approve before merging since we're putting words in their mouths.

@tunetheweb
Copy link
Member

OK let's merge this before the live stream. We can make further adjustments as needed.

@tunetheweb tunetheweb merged commit 77132df into main Dec 10, 2024
7 checks passed
@tunetheweb tunetheweb deleted the perf-2024 branch December 10, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants