The low quality image placeholder pattern is a battletested performance technique. While it might increase measuered time until the onload event, it dramatically increases percieved performance.
This pattern is recommend for above the fold/crictical images.
<img alt="100%x200" src="low-quality.jpg" data-src="normal-quality.jpg" class="lazyload" />
The normal image pattern is can be used for non-critical images or in case there is no low quality image available:
<img class="lazyload" data-src="image.jpg" alt="Desert Road" />
Simply use data-srcset and data-sizes and you can support responsive images.
<img alt="" src="small.jpg" sizes="(min-width: 1000px) 930px, 90vw" data-srcset="small.jpg 500w, medium.jpg 640w, big.jpg 1024w" class="lazyload" />
picture elementThe picture element is also supported. Simply add the lazyload class to the img and use data-srcset on your source and the img element.
<picture> <!--[if IE 9]><video style="display: none"><![endif]--> <source data-srcset="500.jpg" media="(max-width: 500px)" /> <source data-srcset="1024.jpg" media="(max-width: 1024px)" /> <!--[if IE 9]></video><![endif]--> <img src="500.jpg" data-srcset="1200.jpg" class="lazyload" alt="image with artdirection" /> </picture>
automatic sizes feature: In case of lazy loading images the sizes attribute of the img/source elements can be calculated with JS.
This automatic sizes feature is directly included in lazySizes. Simply use the keyword auto inside of the data-sizes attributes (data-sizes="auto").
Important: How sizes is calculated: The automatic sizes calculation takes the width of the image and the width of its parent element and uses the largest number of those two calculated numbers. It's therefore important, that all images are contained in a wrapper that isn't much bigger than the image should shown. Otherwise a wrong (too big) sizes attribute will be calculated.
The autosizes feature makes using responsive images with the right sizes value easy as hell.
<img alt="" data-sizes="auto" src="small.jpg" data-srcset="small.jpg 500w, medium.jpg 640w, big.jpg 1024w" class="lazyload" />
Note that you must use either picturefill or respimage (recommended) for full cross browser support of responsive images.
Iframes can be loaded too:
<iframe data-src="//www.youtube.com/embed/ZfV-aYdU4uE" class="lazyload" frameborder="0" allowfullscreen></iframe>
Simply add a a data-src to your widget (has to be a div/span element) and you are done:
<div data-ride="carousel" data-tag="script" data-src="assets/js/bootstrap.min.js" class="carousel lazyload"> <!-- widget content --> <div>