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

Conditionally load images initially-visible in some breakpoints without lazy-loading performance penalty #1270

Open
westonruter opened this issue Jun 3, 2024 · 1 comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@westonruter
Copy link
Member

Feature Description

If an image is visible in one breakpoint but not another, it should be loaded conditionally. If an image lacks loading=lazy, however, it is loaded unconditionally. Nevertheless, if that image is in the initial viewport, adding loading=lazy is detrimental to page load performance and LCP in particular. Nevertheless, it is possible to conditionally load an image without this performance penalty: add loading=lazy to the image and add a preload link (without fetchpriority=high unless it is LCP) with a media query attribute which identifies the viewport(s) for which the image should be loaded.

In my testing at #117 (comment) I found that adding loading=lazy to the LCP image does not degrade performance if there is a preload link with fetchpriority=high. I presume the same is true for non-LCP images.

It may be a bit confusing when looking at the markup because they may well see an LCP img element which has loading=lazy, but it will still get prioritized via the high-fetchpriority preload link (with a media query). Lighthouse lcp-lazy-loaded audit will need to be updated to account for this case. Specifically, this code:

    const wasLazyLoaded = lcpElementImage.loading === 'lazy';

This should be modified to also check if the lcpElementImage appeared among the preload links with fetchpriority=high, in which case it should be false.

See https://github.com/WordPress/performance/pull/1261/files#r1625015100

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Jun 3, 2024
@westonruter
Copy link
Member Author

Filed Lighthouse issue: GoogleChrome/lighthouse#16034

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant