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

[gatsby-image] Support image loading with JavaScript disabled #3109

Closed
kripod opened this issue Dec 2, 2017 · 8 comments
Closed

[gatsby-image] Support image loading with JavaScript disabled #3109

kripod opened this issue Dec 2, 2017 · 8 comments

Comments

@kripod
Copy link
Contributor

kripod commented Dec 2, 2017

I think that by default, images' src, srcSet and other attributes should be set to the final displayable image instead of e.g. an image with a width of 20 pixels.

If JS is enabled, change to the preview image immediately until the final image is available.

@kripod kripod changed the title [gatsby-image] Support image loading even with disabled JavaScript [gatsby-image] Support image loading with JavaScript disabled Dec 2, 2017
@KyleAMathews
Copy link
Contributor

There's no way afaik to tell the browser to delay loading an image unless we don't render the img element in the HTML.

I'm not sure any image lazy loading technique works with JavaScript disabled.

@kripod
Copy link
Contributor Author

kripod commented Dec 3, 2017

I think that the noscript tag could be used to display the entire image instead of using a preview.

@KyleAMathews
Copy link
Contributor

Ahhhhhh!!!! Yes! Of course! Could you put together a PR adding this?

@kripod
Copy link
Contributor Author

kripod commented Dec 3, 2017

I’ll try my best to do so as soon as I’ll have some free time 😊

@aderaaij
Copy link
Contributor

aderaaij commented Dec 3, 2017

Would this be achieved by something like adding

_react2.default.createElement("noscript", {},
  _react2.default.createElement("img", {
    alt: alt,
    title: title,
    src: image.src,
  })
),   

to the index.js of gatsby-image?

edit: after some tinkering I've discoverd it's not quite that easy. When I add this to the creation of a sizes image for testing, and run a production build and have javascript enabled, I do get an error. I'm going to leave this to smarter people for now, before I'm lost in the rabbithole.

@kripod
Copy link
Contributor Author

kripod commented Dec 3, 2017

I have already created a pull request which solves the issue (tested on the latest version of Firefox).

@aderaaij
Copy link
Contributor

aderaaij commented Dec 3, 2017

👌 that's awesome, thanks! Does it also prevent the base64 or tracedsvg image from showing up?

@kripod
Copy link
Contributor Author

kripod commented Dec 3, 2017

@aderaaij With Firefox, the base64 / traced SVG image is shown until the original gets loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants