Skip to content

Commit 42ad20c

Browse files
committed
This is the new version. New API. New features.
1 parent a835cc5 commit 42ad20c

File tree

9 files changed

+526
-421
lines changed

9 files changed

+526
-421
lines changed

README.md

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,102 @@
11
# Responsively Lazy
22

3-
**The best lazy loading implementation available.**
3+
**Probably the best lazy loading implementation available.**
44

5-
- Handles responsive images
5+
- Perfect for responsive images
66
- Truly lazy (absolutely no unnecessary requests)
77
- **SEO friendly** (valid HTML)
8-
- Supports [WebP](https://en.wikipedia.org/wiki/WebP)
8+
- Supports [WebP](https://en.wikipedia.org/wiki/WebP) and [AVIF](https://en.wikipedia.org/wiki/AVIF)
9+
- Customizable load threshold
10+
- Lazy load HTML
911

1012
<p align="center">
11-
<img src="http://ivopetkov.github.io/responsivelyLazy/poster.jpg" style="max-width:100%;">
13+
<img src="https://ivopetkov.github.io/responsively-lazy-v3/poster.jpg" style="max-width:100%;">
1214
</p>
1315

14-
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/)
16+
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/)
1517

1618
## Download and install
1719

18-
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/)
20+
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/).
1921
```
2022
npm install responsively-lazy
2123
```
24+
25+
The library does not have any dependencies, and it's just 2.5kb when gzipped and minified.
26+
27+
## Usage
28+
29+
* Include the JS file in the head of the document
30+
```html
31+
<script async src="responsively-lazy.min.js"></script>
2232
```
23-
bower install responsively-lazy
33+
34+
* Add the following code for each image
35+
```html
36+
<img src="images/2500.jpg" style="width:100%;aspect-ratio:400/274;" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-responsively-lazy="images/400.jpg 400w, images/600.jpg 600w, images/800.jpg 800w, images/1000.jpg 1000w" />
2437
```
38+
Values to customize:
2539

26-
The library does not have any dependencies, and it's just 1.1kb gzipped and minified.
40+
**aspect-ratio**
2741

28-
## Usage
42+
The aspect ratio of the image (width/height) to reserve space. Skip if you don't know it.
43+
44+
**src**
45+
46+
The default (largest) image size. Will be used by very old browsers, search engines, social networks, etc.
47+
48+
**data-responsively-lazy** (the star of the show)
49+
50+
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.
2951

30-
* Include the css file in the head tag
3152
```html
32-
<link rel="stylesheet" href="responsivelyLazy.min.css">
53+
data-responsively-lazy="images/400.avif 400w avif, images/400.webp 400w webp, images/400.jpg 400w, ..."
3354
```
3455

35-
* Include the js file right before the end of the body tag
56+
**data-responsively-lazy-threshold**
57+
58+
Specify how close to the viewport an image should be to start loading.
3659
```html
37-
<script async src="responsivelyLazy.min.js"></script>
60+
data-responsively-lazy-threshold="500px" // can use percents too
3861
```
3962

40-
* Add the following code for each image
63+
**data-responsively-lazy-type=html**
64+
65+
Lazy load HTML. Can contain JavaScript.
66+
4167
```html
42-
<div class="responsively-lazy" style="padding-bottom:68.44%;">
43-
<img alt="" src="images/2500.jpg" data-srcset="images/400.jpg 400w, images/400.webp 400w, images/600.jpg 600w, images/1000.jpg 1000w" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" />
44-
</div>
68+
<div data-responsively-lazy-type="html" data-responsively-lazy="hello world"></div>
4569
```
46-
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:
70+
71+
**data-responsively-lazy-type=background**
72+
73+
Lazy load image as a background image.
74+
4775
```html
48-
<img class="responsively-lazy" alt="" src="images/2500.jpg" data-srcset="images/400.jpg 400w, images/400.webp 400w, images/600.jpg 600w, images/1000.jpg 1000w" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" />
76+
<div data-responsively-lazy-type="background" data-responsively-lazy="images/400.jpg 400w, images/600.jpg 600w, images/800.jpg 800w, images/1000.jpg 1000w"></div>
4977
```
50-
You can list image versions in the [WebP format](https://en.wikipedia.org/wiki/WebP) which will be used if the browser supports it.
5178

5279
## A new concept
5380

54-
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 `<noscript>` to make your images appear in Google Images. The following code has worked for ages:
81+
Responsively Lazy is very different from the other lazy loading libraries. Others make you break your HTML by removing the `src` attribute, or make you put some tiny version there, or make you use `<noscript>` to make your images appear in search engines (like Google Images). The following code has worked for ages:
5582
```html
5683
<img src="image.jpg" />
5784
```
5885
Let's not break it when we can enhance it.
5986
```html
60-
<img src="image.jpg" data-src="image-200.jpg 200w, image-400.jpg 400w" srcset="..." />
87+
<img src="image.jpg" data-responsively-lazy="image-200.jpg 200w, image-400.jpg 400w" srcset="..." />
6188
```
6289

6390
## Browser support
6491

65-
The lazy loading works in browsers supporting the srcset attribute. As of December 2017 that's [86.78%](http://caniuse.com/#feat=srcset). Unsupported browsers will load the image in the src attribute. That's the image search engines and social networks will find, so it's better to make it high resolution.
92+
The lazy loading works in browsers supporting the srcset attribute and JavaScript. As of December 2023 that's [97.6%](https://caniuse.com/#feat=srcset). Unsupported browsers will load the image in the src attribute. That's the image search engines and social networks will find, so it's better to make it high resolution.
6693

6794
## DOM changes
6895

6996
The library will listen for DOM changes and you can also trigger visible images loading by calling `responsivelyLazy.run()`.
7097

7198
## License
72-
Free to use under the [MIT license](http://opensource.org/licenses/MIT).
99+
Free to use under the [MIT license](https://opensource.org/licenses/MIT).
73100

74101
## Got questions?
75-
You can find me at [@IvoPetkovCom](https://twitter.com/IvoPetkovCom) and [ivopetkov.com](http://ivopetkov.com)
102+
You can find me at [@IvoPetkovCom](https://twitter.com/IvoPetkovCom) and [ivopetkov.com](https://ivopetkov.com)

bower.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "responsively-lazy",
33
"title": "Responsively Lazy",
4-
"version": "2.0.2",
4+
"version": "3.0.0",
55
"description": "Lazy load responsive images",
66
"homepage": "http://ivopetkov.com/b/lazy-load-responsive-images/",
77
"author": {

0 commit comments

Comments
 (0)