Repository navigation
Don't lazy-load the image people see first (Web HIG tip #15) #32
frozonfreak
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Open your home page or a product page on a phone, on a slow connection. The headline and buttons show up, but the big hero image stays blank for a beat longer than everything else. Look at its markup and you'll often find
loading="lazy", added to every<img>on the site by a template, a plugin, or a well-meant "lazy-load all images" change.Web HIG tip #15 (Quick #84): Lazy-load below-the-fold media; never lazy-load the LCP candidate.
Why it matters
Lazy loading is a trade: the browser waits to fetch an image until it's close to the viewport. That's a win for images further down the page, and a loss for the one people see first:
data-srcthat a script swaps in, the browser can't find it in the HTML at all until that script runsThe full HIG covers the image side of this in §2.1, Document Fundamentals, under responsive images: lazy-load non-critical images where appropriate, and avoid lazy-loading the LCP candidate and other immediately needed content. The LCP candidate SHOULD be discoverable early and MAY use
fetchpriority="high"when appropriate. Quick #84 is Quick-only guidance, with no rule ID of its own. It pairs with Quick #83, which asks every image to declare its dimensions or aspect ratio, and with Quick #82's LCP target of 2.5 s or less.The rule of thumb
Ask: will this image be on screen before anyone scrolls? If yes, don't lazy-load it.
This page looks fine on a fast laptop, but the hero waits for layout and for a script before it even starts downloading:
Load the hero early and lazy-load what's further down:
The page looks the same. The difference is when each image starts downloading.
Do this instead
loadingoff the LCP image (the default iseager), give it a realsrcorsrcsetin the HTML, and considerfetchpriority="high". Browsers that don't supportfetchpriorityignore itloading="lazy"to images and iframes that sit well below the first view: long article bodies, comment sections, footers, embedded maps and video players<video>further down the page, usepreload="none"(or"metadata") and aposterimage.loading="lazy"on<video>is newly specified but only some browsers support it so far, so treat it as a bonus, not the fixwidthandheight(or a CSSaspect-ratio) so the page doesn't jump when they arrivebackground-image, the browser only finds it after the CSS has loaded. Use an<img>instead, or add<link rel="preload" as="image">for itQuick check for your app
Open your main pages (say, example.com and example.com/products) at a phone width and at a desktop width. In the browser's developer tools, find the LCP element in a performance recording, then check its markup: no
loading="lazy", and a URL that's in the HTML rather than added by a script. Scroll down and watch the network panel: images further down should only start loading as you get near them. A tool can flag a lazy-loaded LCP image in a single lab run, but only checking the real LCP element on your own pages, at the widths people use, shows which image needs to load first.The Web HIG is an open set of guidelines for how the web should behave, not a component library. Design systems define how it looks. The Web HIG defines how it behaves.
All reactions