Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome version 40 srcset attribute problems

I'm seeing a lot of inconsistencies with srcset attribute on img tags (responsive images) in Chrome 40.0.2214.91

Before I updated to Chrome v40 (I was on ~39), srcset attribute worked fine and would swap the image upon browser resize. Now, sometimes, the smaller version of the image will display if I have the browser set to the desired width then refresh the page. Other times it will not work whatsoever.

Testing jsbin: http://jsbin.com/hulaconake/1/edit?html,output

Image tag I have:

<img srcset="http://placehold.it/300x200 300w, http://placehold.it/500x400 500w">

I'm also testing this in another env with non-Placehold.it images, and using Picturefill.js http://scottjehl.github.io/picturefill/

I'm not having any issues in FF or Safari (both using picturefill).

iOS Chrome has similar problems.

Is my syntax wrong? Is there something going on I don't know about?

like image 684
Zeb Pykosz Avatar asked Jan 26 '15 17:01

Zeb Pykosz


1 Answers

It's a feature not a bug. Chrome does not switch the size because Chrome already has a larger image in cache, so there is no need to download new data of the same image.

In case you want to use different images or same image with different crops, use the picture element.

Responsive images can be technically differentiated between 2 types.

  • srcset with source descriptors (let the browser choose the right image based on screen size/resolution, bandwidth…):
    • density descriptor (x) (for static image sizes, Retina vs. normal resolution)
    • width descriptor (w) and the corresponding sizes attribute (for flexible, responsive / adaptive images (automatically also includes Retina optimization)
  • and the picture element with its source[media] children (gives the author control about what srcset should be chosen by the browser depending on specific media queries)

So img[srcset] is for resolution switching and picture is for different images reacting to your design

like image 187
alexander farkas Avatar answered Oct 26 '22 21:10

alexander farkas