question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Defer offscreen images' doesn't consider 'loading=lazy' attribute

See original GitHub issue

I’m seeing some odd behaviour with Native Lazy Loading that has a JS fallback.

The source code we use is:

<img src="placeholder.jpg" data-src="image.jpg" loading="lazy" alt="" class="">

The JS identifies images with loading=lazy. If there’s native support it makes the data-src the src and does nothing else. We then use Intersection Observer for other browsers.

However, Lighthouse is flagging images that are using this pattern as not being lazy loaded.

It does seem to be the case that images outside of the viewport are indeed loaded before they’re seen, so on page load. These are the images that Lighthouse picks up on. That said, they are loaded with a low priority and only fetched after the onload event.

We can’t control this behaviour. This is hammering our performance scores so it would be amazing to shed some light on why (or, indeed, are we doing something wrong). It feels unfair that a mechanism we can’t control is being flagged as an issue by Lighthouse. Unless we are doing something wrong here.

Unfortunately if I can’t resolve this issue I have to move back to JS lazy loading. An example site that has this issue can be found here: https://www.drakes.com/clothing

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
domfarolinocommented, Dec 13, 2019

It is true “auto” has been removed from the spec (for now), but we’re planning on re-introducing it later on. Just for completeness, Chrome ships (and defaults to) “auto”. For more info see https://github.com/GoogleChrome/web.dev/pull/1971#issuecomment-565630653.

2reactions
paulirishcommented, Dec 6, 2019

If someone is using loading=lazy on an image we definitely shouldn’t flag that in offscreen-images.

~web.dev/blog offers a repro for this.~ the drakes repro mentioned above is great.

To be consistent with our caching audit, etc, we should filter out any image that has a valid loading attribute value. (Those appear to be lazy, eager or auto.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Defer Offscreen Images (With and Without Plugins)
Google recommends to “Consider lazy-loading offscreen and hidden images after all critical resources have finished loading to lower time to interactive”.
Read more >
How to Lazy Load Offscreen Images (5 Proven Techniques)
Lazy loading offscreen images refers to using a set of techniques to load only the images that visitors are currently looking at.
Read more >
Lighthouse: Defer offscreen images - GTmetrix
Lazy-loading offscreen images ensures that they only load when they are needed, as in appearing into view when your visitor scrolls down the...
Read more >
Fix Defer offscreen images lighthouse warning
Lazy loading means that images that are not located in the visible part of the page may be loaded at a later time,...
Read more >
How to Defer Offscreen Images in WordPress With Lazy Loading
Prevent Images from Loading the Normal Way · Determine How the Browser will Detect Images in the Viewport. JavaScript Event Handler; The ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found