Gatsby: [gatsby-image] Support image loading with JavaScript disabled

Created on 3 Dec 2017  路  8Comments  路  Source: gatsbyjs/gatsby

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.

Most helpful comment

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

All 8 comments

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.

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

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

I鈥檒l try my best to do so as soon as I鈥檒l have some free time 馃槉

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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

magicly picture magicly  路  3Comments

jimfilippou picture jimfilippou  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments

brandonmp picture brandonmp  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments