Option to stop redundant download of small images. - #77
Conversation
This option stops Imager.js downloading a new image when a higher resolution copy has already been downloaded. This can occur when a mobile device is rotated from landscape to portrait. Upscaling to larger images is unchanged.
|
Thanks for the contribution :-) Have you seen #48? I feel it has the same purpose. |
|
I hadn't seen that issue. I agree, this commit serves exactly that purpose. |
There was a problem hiding this comment.
Why doing that for IE8? A DOM element does not support JS attributes?
There was a problem hiding this comment.
It's key to check the naturalWidth of the image as opposed to the clientWidth as it represents the image's true size, unscaled by DOM or CSS. IE doesn't support the naturalWidth/naturalHeight properties until IE9.
|
Cool so @nkp if you can remove the bits related to the "option" thing, I'll write the tests before merging that into |
And fixes 'strict' warning for getNaturalWidth definition.
There was a problem hiding this comment.
@nkp any chance you explain this special case for IE8? (I mean why not using the DOM Element own JS property?)
There was a problem hiding this comment.
It's key to check the naturalWidth of the image as opposed to the clientWidth or width as it represents the image's true size, unscaled by DOM or CSS. IE doesn't support the naturalWidth/naturalHeight properties until IE9.
The computed width for download is based on the scaled clientWidth of the image and as such will always be greater-than or equal to the clientWidth.
I decided that supporting IE8 was worth the trivial work around.
There was a problem hiding this comment.
Oh ok it's a real attribute computed by the browser! I did not know it :-D
A very quick cross-browser shortcut would be to store only the biggest availableWidths value used and update the src url only if the new value is bigger.
Or not to care about IE8 for this feature? @Integralist, is the IE8 support going to last long at BBC News?
|
@oncletom sadly... Yes :-( it is a trivial additional piece of code but will make a big difference overall I think considering there are still lots of organisations who still need IE8 support. |
|
Okay that makes sense :-) I'll merge that before the next release, adding some relevant tests at the same time (no need to rebase @nkp unless this is some delight which makes your day :-p) |
|
@nkp I'll merge this one once the two previous quoted issues gets some feedbacks. |
And fixes 'strict' warning for getNaturalWidth definition.
|
This has been merged in master. Slight change of behaviour: the image It might be a breaking change so for now it's in master and behind the |
This option stops Imager.js downloading a new image when a higher
resolution copy has already been downloaded. This can occur when a
mobile device is rotated from landscape to portrait.
Upscaling to larger images is unchanged.