srcset-polyfill icon indicating copy to clipboard operation
srcset-polyfill copied to clipboard

Chrome 36 supports srcset attribute but not its functionality

Open AnJ95 opened this issue 11 years ago • 3 comments

I am encountering a problem regarding your polyfill which is and will be extremely useful for fallbacks even in coming years. Now the problem is, that Google Chrome 36.0.1985.125 seems to have added the srcset attribute to images even though it is not used. Therefore,

"srcset" in document.createElement("img")

returns true in Chrome.. Might there be a way to specify that condition?

AnJ95 avatar Aug 08 '14 07:08 AnJ95

srcset is now supported in Chrome, but according to caniuse, Safari's implementation is incomplete.

The test should be rewritten to do proper feature detection. For instance,

var img = document.createElement("img");
img.setAttribute("srcset", "data:… 10w, data:… 20w, data:… 30w");
img.setAttribute("sizes", "10px");
// run through your polyfill and see if the browser displayed the same image
// if does, try again with "2x" and "3x" instead of "20w, …30w"
// if both tests pass, don't install the polyfill

appsforartists avatar Nov 04 '14 21:11 appsforartists

FWIW, I came to this repo after a quick Google search for a srcset polyfill, but this looks more robust:

http://scottjehl.github.io/picturefill/

I'll likely go that way for my iOS 8 supporting-needs.

appsforartists avatar Nov 04 '14 21:11 appsforartists

Thanks.

I'm actually gonna put up a notice saying do not use for this repo as unfortunately I don't have the time to maintain it. Feel free to fork it though.

Of all the implementations I have seen this is the one that has caught my eye. Better than Piturefill in my opinion. https://github.com/aFarkas/respimage

JimBobSquarePants avatar Nov 04 '14 21:11 JimBobSquarePants