Skip to content

Add support for native lazy loading to gatsby-image #13201

@KyleAMathews

Description

@KyleAMathews

https://twitter.com/addyosmani/status/1114777583302799360

We'll want to feature detect this using the code in Addy's blog post:

if ('loading' in HTMLImageElement.prototype) { 
    // Browser supports `loading`, don't setup IntersectionObserver
} else {
   // Use existing IntersectionObserver code
}

If lazy-loading exists, then we'll want to use it, if not, we'll continue to use our IntersectionObserver setup.

For images using the critical prop, we should use loading="eager" and for other images, we should use loading="lazy" — this should replicate our existing semantics.

<!-- Lazy-load an offscreen image when the user scrolls near it -->
<img src="unicorn.jpg" loading="lazy" alt=".."/>

<!-- Load an image right away instead of lazy-loading -->
<img src="unicorn.jpg" loading="eager" alt=".."/>

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions