react-lazyload icon indicating copy to clipboard operation
react-lazyload copied to clipboard

Images using srcset attribute download both 1x and 2x versions in Safari and Firefox

Open jasonbarry opened this issue 6 years ago • 2 comments

When wrapping LazyLoad around an image that utilizes the srcset attribute, both the 1x and 2x versions download in Safari and Firefox. Chrome seems to do the right thing and only download one version.

<LazyLoad height={height} once offset={100}>
  <img
    alt={alt}
    src="/path/to/image.png"
    srcSet="/path/to/image.png 1x, /path/to/[email protected] 2x"
    height={height}
    width={width}
  />
</LazyLoad>

According to the devtools, in Safari and Firefox both /path/to/image.png and /path/to/[email protected] get download as you scroll past. I would expect on my Retina laptop only the 2x image to get downloaded (Chrome's behavior).

jasonbarry avatar Jul 20 '18 22:07 jasonbarry

I'm also getting this, though only on Safari. Did you find a solution?

dertel avatar Mar 16 '21 19:03 dertel

OK I found a solution. This is crazy but if you change the order of the attributes to sizes, srcSet, THEN src, then it fixes the problem for me. For example

<LazyLoad height={height} once offset={100}>
  <img
    alt={alt}
    sizes{...}
    srcSet="/path/to/image.png 1x, /path/to/[email protected] 2x"
    src="/path/to/image.png"
    height={height}
    width={width}
  />
</LazyLoad>

dertel avatar Mar 16 '21 19:03 dertel