Lazy load responsive images
github.com
github.com
If you have a bunch of images you don't want to wait to load them until in view especially on a slow connection. If you lazy load the images then that means every time the user scrolls they have to wait for an image. No one is going to wait for your image to load, so they will scroll on. You then cause a bottleneck in your javascript because the user is scrolling and you are using JS to download images which is not optimal.
The experience you want is to load the first image and then load then next image before the user gets to it so that it is ready when the user scrolls. Our browsers do a great job of this already. Don't reinvent the wheel. Our browsers have been optimized to download images the right way. And if you want to save bandwidth then use responsive images and let the browser determine the best size to download.
I've implemented lazy load on mobile and learned this first hand. I thought I needed lazy load, but to my surprise, the browser actually knows how to load images the right way. My app actually had less jank and loaded images faster when I left the images up to the browser.
Stop over engineering image loading please :-)
The technique here is an excellent way to load only the right size images for different devices.
It works in about 65% of browsers and has excellent fallback characteristics in others.
Read the bottom of the blogpost here for details:
http://ivopetkov.com/b/lazy-load-responsive-images/
P.S. I'm totally with you on pointless lazy-loading - the browser should figure out what is sensible to load based on available bandwidth and where I have scrolled to...
Isn't this exactly the "pointless lazy-loading" that you and the OP are complaining about? If what you want is to "load only the right size images for different devices," and you're targeting browsers that support srcset, you can just use srcset.
No, it's not pointless; I think it's actually quite useful if you rely on Javascript, which some say is the worst thing in the world... but after using React I've been persuaded for complex interfaces it can provide clear advantages over progressive enhancement.
Sorry, what browsers? There is no such thing. Even virtually everyone's phone runs javascript.
The only way you are running a modern browser without JS is if you've (as a power-user) turned it off. In which case you need to turn it back on when you encounter weirdness on a website that expects that your browser behaves like a normal modern browser. If you run your browser without JS (like I do), then you encounter this situation frequently and it's part of the tradeoff of controlling exactly what code runs during your web experience.
If your page has lots of search results and lots of images it really saves a huge amount and makes the page feel much lighter.
- The data:image in the srcset attribute shows transparent image and prevents loading the image in the src attribute in modern browsers
- The image in the src is attribute is used if the browser does not support the srcset attribute or when the page is scanned by social networks and read-it-later tools.
It's a strict polyfill of the picture / srcset standards, which already have broad, native browser support: http://caniuse.com/#search=picture|srcset
How can this claim to be the "best" when it's browser support is barely over 50%? Here's the one that I feel is "best" after trying many, it supports IE7, which is effectively 100% browser support as far as I'm concerned.
At the same time, one could use something like ImageMagick to find out the dimensions of the picture and set this ratio programatically (http://stackoverflow.com/questions/16266933/rmagick-how-do-i...)
Bug: When the same image is found elsewhere on the page, Firefox doesn't bother using smooth interpolation when downscaling.
[Edit - workaround is to avoid cache, as in cat.jpg?01 ; cat.jpg?02 ]
Look at the cat's whiskers, they look rough in the smallest image. They should look smooth. So using Firebug I removed all other images on the page except the first smallest version. Hey presto, the whiskers are suddenly smooth.
http://ivopetkov.github.io/responsivelyLazy/
Of course, IE is a lot worse - its scaling is rough all the time regardless.