diff --git a/README.md b/README.md index 0158886..f0bcdbb 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,102 @@ # Responsively Lazy -**The best lazy loading implementation available.** +**Probably the best lazy loading implementation available.** -- Handles responsive images +- Perfect for responsive images - Truly lazy (absolutely no unnecessary requests) - **SEO friendly** (valid HTML) -- Supports [WebP](https://en.wikipedia.org/wiki/WebP) +- Supports [WebP](https://en.wikipedia.org/wiki/WebP) and [AVIF](https://en.wikipedia.org/wiki/AVIF) +- Customizable load threshold +- Lazy load HTML

- +

-You can find a demo at [http://ivopetkov.github.io/responsivelyLazy/](http://ivopetkov.github.io/responsivelyLazy/) and learn how the magic works at [http://ivopetkov.com/b/lazy-load-responsive-images/](http://ivopetkov.com/b/lazy-load-responsive-images/) +You can find a demo at [ivopetkov.github.io/responsively-lazy-v3/](https://ivopetkov.github.io/responsively-lazy-v3/) and learn how the magic works at [ivopetkov.com/responsively-lazy/](https://ivopetkov.com/responsively-lazy/) ## Download and install -Download the minified [css](https://raw.githubusercontent.com/ivopetkov/responsively-lazy/master/responsivelyLazy.min.css) and [js](https://raw.githubusercontent.com/ivopetkov/responsively-lazy/master/responsivelyLazy.min.js) files or install through [npm](https://www.npmjs.com/) and [bower](http://bower.io/) +Download the minified [JS file](https://raw.githubusercontent.com/ivopetkov/responsively-lazy/master/responsively-lazy.min.js) or install via [npm](https://www.npmjs.com/). ``` npm install responsively-lazy ``` + +The library does not have any dependencies, and it's just 2.5kb when gzipped and minified. + +## Usage + +* Include the JS file in the head of the document +```html + ``` -bower install responsively-lazy + +* Add the following code for each image +```html + ``` +Values to customize: -The library does not have any dependencies, and it's just 1.1kb gzipped and minified. +**aspect-ratio** -## Usage +The aspect ratio of the image (width/height) to reserve space. Skip if you don't know it. + +**src** + +The default (largest) image size. Will be used by very old browsers, search engines, social networks, etc. + +**data-responsively-lazy** (the star of the show) + +Must contain a list of image versions separated by commas. Each version must contain a path to the image and its size. Optionaly you can specify the file type (webp or avif). The first supported format for the selected width is used. -* Include the css file in the head tag ```html - +data-responsively-lazy="images/400.avif 400w avif, images/400.webp 400w webp, images/400.jpg 400w, ..." ``` -* Include the js file right before the end of the body tag +**data-responsively-lazy-threshold** + +Specify how close to the viewport an image should be to start loading. ```html - +data-responsively-lazy-threshold="500px" // can use percents too ``` -* Add the following code for each image +**data-responsively-lazy-type=html** + +Lazy load HTML. Can contain JavaScript. + ```html -
- -
+
``` -The things to customize are the **padding-bottom** style, and the values of the **src** and **data-srcset** attributes. If you don't know the image aspect ratio you can skip the div tag and move the responsively-lazy class to te img tag: + +**data-responsively-lazy-type=background** + +Lazy load image as a background image. + ```html - +
``` -You can list image versions in the [WebP format](https://en.wikipedia.org/wiki/WebP) which will be used if the browser supports it. ## A new concept -Responsively Lazy is very different from the other lazy loading libraries. They make you break your HTML by removing the `src` attribute, or make you put tiny version there or make you use `