-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Allow optional disabling of lazy loading images in SSR to improve performance #4297
Comments
I'm looking into issues related to this. Is there a general feeling as to the mechanism for opting-in or opting-out of lazy-loading? (what should the default be)? It seems that a global config is too limiting. |
We want the default to stay lazy loading. This issue is about adding the ability to optionally opt-out of lazy loading by setting a prop in gatsby-image. If you'd like to tackle adding a PR for this that'd be great! |
@tbrannam @KyleAMathews maybe the API could look something like this? import React from 'react';
import Image from 'gatsby-image';
export default ({ fluid }) => (
<div>
<h1>Hero Section</h1>
<Image fluid={fluid} critical />
</div>
); This would signal that it's a critical image in a human-readable way, allow us to skip lazy-loading in SSR, and allows normal client-side lazy-loading. Is there a better prop name? Anything additional this feature would need to account for? |
Critical is a user-friendly way to describe it 👍 |
Things are progressing well - but I think there's a related issue regarding webp support. The default SSR behavior for webp is assume it is not supported. So the non-lazy loaded markup would be default only include a jpeg - and likely switch to webp on re-render. see: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-image/src/index.js#L79 I'm experimenting with Additionally if lazy-loading is skipped - there is no need for a corresponding Any objections to this approach?
|
Yeah, that's the right way to do webp — I just skipped figuring out all that since we were lazy loading everything anyways, it was simpler to just do the webp test in the browser :-) |
I've got the baseline working in v2 - but have come across an issue related to the role of placeholders in 'critical' resources. SSR rendered img
-or -
|
Yeah, having placeholders is still useful for critical images. Ideally we can support them still. |
Fair enough - although I'm at a loss on how to maintain the cross-fade effect when the images are loaded before the components mount. |
At best it's going to be a race condition whether the base64 image or background placeholder fades to the loaded image. 'onLoad' won't be called since React isn't live. If it is acceptable to load without the cross-fade I think things will work out. Is there a supported way to keep React from stripping onLoad from |
|
It appears that |
It'd query all the images in the dom and add |
PR #7083 addresses this. using |
Address #4297 * Add `critical` attribute to opt-out of lazy-loading behavior * Picture tag to allow browser to select best matching file format (webp detection) * if fadeIn is true (default) - then the loaded image still will not appear until after the component is mounted ``` <Img fixed={images.file1.childImageSharp.fixed} /> <Img fixed={images.file1.childImageSharp.fixed} /> <Img fixed={images.file2.childImageSharp.fixed} critical fadeIn={false}/> <Img fixed={images.file2.childImageSharp.fixed} critical/> ```
This can be closed now since #7083 was merged right? |
I would think so |
Yup, thanks everyone! |
In #4270 (comment), @KyleAMathews said:
I'm capturing this as its own issue in hopes that someone wants to pick it up.
The text was updated successfully, but these errors were encountered: