Skip to content

Commit 69becbe

Browse files
authored
For v3.5.0 (#120)
1 parent 0df8ae6 commit 69becbe

15 files changed

+415
-429
lines changed

.build/.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"max-depth": "error",
7676
"max-len": "off",
7777
"max-lines": "off",
78-
"max-lines-per-function": "error",
78+
"max-lines-per-function": ["error", 100],
7979
"max-nested-callbacks": "error",
8080
"max-params": "off",
8181
"max-statements": "off",

README.md

+63-65
Original file line numberDiff line numberDiff line change
@@ -5,138 +5,137 @@
55
[![NPM](https://img.shields.io/npm/l/@shinsenter/defer.js)](https://code.shin.company/defer.js/blob/master/LICENSE)
66
[![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@shinsenter/defer.js)](https://snyk.io/advisor/npm-package/@shinsenter/defer.js)
77
[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/shinsenter/defer.js)](https://www.codefactor.io/repository/github/shinsenter/defer.js)
8-
9-
* * *
10-
118
[![GitHub Release Date](https://img.shields.io/github/release-date/shinsenter/defer.js)](https://code.shin.company/defer.js/releases)
129
[![GitHub package.json version](https://img.shields.io/github/package-json/v/shinsenter/defer.js)](https://code.shin.company/defer.js/releases)
1310
[![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@shinsenter/defer.js)](https://www.npmjs.com/package/@shinsenter/defer.js)
1411
[![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/@shinsenter/defer.js)](https://www.jsdelivr.com/package/npm/@shinsenter/defer.js)
1512

13+
14+
* * *
15+
16+
17+
## Introduction
18+
19+
Lagging Big CSS files, slow JavaScript, or bulky media resources can cause issues with your website's Web Vitals, leading to a slow and frustrating user experience. But what if you could fully defer these resources and improve your website's load speed?
20+
21+
By using Defer.js, you can say goodbye to these issues! With its lazy loading capabilities, dependency-free design, lightning-fast performance, and hard-won experience, Defer.js is the perfect solution for optimizing your website's Web Vitals. Whether you're using a modern or legacy browser, Defer.js makes it easy to enhance your website's user experience with lightning-fast loading times.
22+
1623
[![NPM](https://nodei.co/npm/@shinsenter/defer.js.png?downloads=true)](https://www.npmjs.com/package/@shinsenter/defer.js)
1724

1825
- **Package**: [@shinsenter/defer.js](https://www.npmjs.com/package/@shinsenter/defer.js)
19-
- **Version**: 3.4.0
26+
- **Version**: 3.5.0
2027
- **Author**: Mai Nhut Tan <[email protected]>
21-
- **Copyright**: 2022 AppSeeds <https://code.shin.company/>
28+
- **Copyright**: 2019-2023 SHIN Company <https://code.shin.company/>
2229
- **License**: [MIT](https://code.shin.company/defer.js/blob/master/LICENSE)
2330

24-
> [NEED HELP] Please help me improve the documentation and examples. I appreciate your love and support.
31+
---
2532

26-
* * *
33+
## Document in other languages
2734

35+
> [NEED HELP] Let's make the documentation and examples better together!
2836
29-
## Introduction
37+
### 日本語
3038

31-
Big CSS files, slow JavaScript (third-party add-ons, etc.),
32-
or media resources (photos, videos, iframes) on your website may cause
33-
[Web Vitals](https://web.dev/vitals/) issues in real scenarios.
39+
日本人のはこちらの記事を参考にしていただければ幸いです。
3440

35-
Fully deferring (lazy loading) those resources may help your website
36-
reduce those Web Vitals issues, or even deliver faster page load speed.
41+
- アタルさんの[Defer.js ドキュメント (日本語訳)](https://blog.gadgets-geek.net/2023/02/deferjs-doc-japanese.html)
42+
- あトんさんの[記事](https://www.heavy-peat.com/2022/02/defer.html)
43+
- リモスキさんの[記事](https://www.limosuki.com/2022/06/twitter-lazyload-deferjs.html)
3744

38-
You would be happy, and your customers would be happy, too.
45+
#### Credits
3946

40-
> [Japanese] 日本人の方は[こちらの記事](https://www.limosuki.com/2022/06/twitter-lazyload-deferjs.html)をご参考にして頂ければと思います。
47+
I would like to express warm thanks to [@Ataruchi](https://twitter.com/Ataruchi), [@HeavyPeat](https://twitter.com/HeavyPeat) and [Limosuki](https://www.limosuki.com/) for their articles in Japanese.
4148

49+
***
4250

43-
## Why you should consider using Defer.js?
51+
## Why Choose Defer.js
4452

45-
- 🧩 Lazy load almost anything
46-
- 🚀 Dependency-free, no jQuery, amazing fast
53+
- 🧩 Lazy load almost anything with ease
54+
- 🚀 Lightweight and fast, with no dependencies
55+
- 🤝 Effortlessly integrates with your favorite frameworks
56+
- 🔰 Easy to use, even for beginners
4757
- ⚡️ Super tiny (minzipped size is around 1KB)
48-
- 🦾 Hardened (over 3 years old and used in many apps)
49-
- 🎯 [Core Web Vitals](https://web.dev/vitals/) friendly
50-
- 🤝 Works well with your favorite frameworks
51-
- 🔰 Very easy to use
52-
- 📱 Smartphone browser friendly
53-
- ✅ Supports legacy browsers (IE9+)
58+
- 🦾 Optimized for the latest Web Vitals standards
59+
- 📱 Optimized for use on smartphones
60+
- ✅ Supports legacy browsers like Internet Explorer 9
5461

62+
<sup>*Legacy browsers like Internet Explorer 9 require `IntersectionObserver` polyfill.</sup>
5563

56-
## Browser support
64+
## Browser Support
5765

58-
The library works perfectly on any modern browser.
59-
It also works on legacy browsers like Internet Explorer 9
60-
<sup>* (with `IntersectionObserver` polyfill library)</sup>.
61-
62-
- 🖥 IE9+ / Microsoft EDGE
66+
Defer.js is compatible with all modern browsers, including:
67+
- 🖥 IE9+ / Edge
6368
- 🖥 Firefox 4+
6469
- 🖥 Safari 3+
6570
- 🖥 Chrome
6671
- 🖥 Opera
6772
- 📱 Android 4+
6873
- 📱 iOS 3.2+
6974

70-
7175
## Getting started
7276

77+
Defer.js is an easy-to-use library that will help boost your website's performance by reducing loading times. Here's how to get started:
78+
7379
### Basic
7480

75-
Just put a `<script>` tag pointing to the library URL just below the opening `<head>` tag of your page.
81+
Add the Defer.js library to your page by including a `<script>` tag just below the opening `<head>` tag.
7682

7783
```html
7884
<head>
7985
<meta charset="UTF-8" />
8086
<title>My Awesome Page</title>
8187

82-
<!-- Put defer.min.js here -->
83-
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@3.4.0/dist/defer.min.js"></script>
88+
<!-- Add Defer.js here -->
89+
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@3.5.0/dist/defer.min.js"></script>
8490

8591
<!-- ... -->
8692
</head>
8793
```
8894

8995
### Inlining the library
9096

91-
Because `defer.min.js` is optimized to a very tiny file size, you can even inline entire the library to save one HTTP request.
97+
To save an HTTP request, you can even inline the entire Defer.js library by copying its content from the [defer.min.js](https://cdn.jsdelivr.net/npm/@shinsenter/[email protected]/dist/defer.min.js) and replacing the comments in the script tag with its content.
9298

9399
```html
94100
<head>
95101
<meta charset="UTF-8" />
96102
<title>My Awesome Page</title>
97103

98-
<!-- Copy the script from the below URL -->
99-
<!-- https://cdn.jsdelivr.net/npm/@shinsenter/[email protected]/dist/defer.min.js -->
100-
<script>/* then replace this comment block with the content of defer.min.js */</script>
104+
<!-- Add the Inlined Defer.js here -->
105+
<script>/* Defer.js content goes here */</script>
101106

102107
<!-- ... -->
103108
</head>
104109
```
105110

106111
### Compatibility with older versions
107112

108-
If you have no time to upgrade from an older version,
109-
just use `defer_plus.min.js` instead of `defer.min.js`.
113+
If you're using an older version of Defer.js, you can use `defer_plus.min.js` instead of `defer.min.js`.
110114

111115
```html
112116
<head>
113117
<meta charset="UTF-8" />
114118
<title>My Awesome Page</title>
115119

116120
<!-- Put defer_plus.min.js here -->
117-
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@3.4.0/dist/defer_plus.min.js"></script>
121+
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@3.5.0/dist/defer_plus.min.js"></script>
118122

119123
<!-- ... -->
120124
</head>
121125
```
122126

123127
### For OLD browsers (such as IE9)
124128

125-
To take advantage of native performance for legacy browsers (such as IE9)
126-
that don't support `IntersectionObserver` feature,
127-
you should load `IntersectionObserver` polyfill library
128-
right after the `defer.min.js` script tag as the following example:
129+
To enhance performance for legacy browsers that don't support the `IntersectionObserver` feature, you can load the IntersectionObserver polyfill library after the `defer.min.js` script tag.
129130

130131
```html
131-
<script>/* the content of defer.min.js */</script>
132+
<script>/* Defer.js content */</script>
132133

133-
<!-- If legacy browsers like Internet Explorer 9 still need to be supported -->
134-
<!-- Please put IntersectionObserver polyfill right after the Defer.js script tag -->
135-
<script>'IntersectionObserver'in window||document.write('<script src="https://cdn.jsdelivr.net/npm/@shinsenter/[email protected]/dist/polyfill.min.js"><\/script>');</script>
134+
<!-- Add the IntersectionObserver Polyfill for legacy browsers -->
135+
<script>'IntersectionObserver'in window||document.write('<script src="https://cdn.jsdelivr.net/npm/@shinsenter/[email protected]/dist/polyfill.min.js"><\/script>');</script>
136136
```
137137

138-
*HINT*: Modern browsers support `IntersectionObserver` feature,
139-
so you don't have to be concerned about it if you don't care about IE users.
138+
*NOTE*: Modern browsers support the `IntersectionObserver` feature, so you don't have to worry about adding the polyfill if you don't have legacy browsers in mind.
140139
## Functions
141140

142141
* [Defer(func, [delay], [waitForUserAction])](#Defer) ⇒ <code>void</code>
@@ -678,7 +677,7 @@ he/she will see a message as soon as an element with `id="surprise-me"` appears.
678677
```html
679678
<script>
680679
Defer.dom('#surprise-me', 1000, 'seen', function(node) {
681-
alert('Yay!\n\nYou have seen all examples.\nHave fun with Defer.js!');
680+
alert('Yay!\nYou have seen all examples. Have fun with Defer.js!');
682681
});
683682
</script>
684683
```
@@ -817,7 +816,8 @@ AddThis add-on will not be loaded until the user starts interacting with the pag
817816
<div class="demo-addthis"></div>
818817

819818
<script>
820-
var fileUrl = 'https://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5c68e61cf456f1cb';
819+
var ADDTHIS_ID = 'ra-5c68e61cf456f1cb';
820+
var fileUrl = 'https://s7.addthis.com/js/300/addthis_widget.js#pubid=' + ADDTHIS_ID;
821821
var loaded = false;
822822
823823
Defer.js(fileUrl, 'addthis-js', 0, function() {
@@ -1040,30 +1040,28 @@ A [Function](#Function) receives a DOM [Node](#Node) object as its argument.
10401040

10411041
## Community
10421042

1043-
As an open-source project, we'd appreciate any help and contributions!
1044-
1045-
[![Become a stargazer](https://img.shields.io/badge/Become-Stargazer-yellow)](https://code.shin.company/defer.js/stargazers) [![Report an issue](https://img.shields.io/badge/New-Discussions-green)](https://code.shin.company/defer.js/discussions/new) [![Join us on Gitter](https://badges.gitter.im/shinsenter/defer.js.svg)](https://gitter.im/shinsenter/defer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join us on Discord](https://img.shields.io/discord/962919929307357234?color=blueviolet)](https://discord.com/channels/962919929307357234/1000635855712559165)
1043+
Join our vibrant community of open-source contributors and make your mark on the project! We welcome all forms of contributions and support.
10461044

1047-
We should follow the standard [GitHub pull request process](https://help.github.com/articles/about-pull-requests). I'll try to review your contributions as soon as possible.
1045+
[![Become a Stargazer](https://img.shields.io/badge/Become-Stargazer-yellow)](https://code.shin.company/defer.js/stargazers) [![Report an issue](https://img.shields.io/badge/New-Discussions-green)](https://code.shin.company/defer.js/discussions/new) [![Join us on Gitter](https://badges.gitter.im/shinsenter/defer.js.svg)](https://gitter.im/shinsenter/defer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join us on Discord](https://img.shields.io/discord/962919929307357234?color=blueviolet)](https://discord.com/channels/962919929307357234/1000635855712559165)
10481046

1047+
We use the standard [GitHub pull request process](https://help.github.com/articles/about-pull-requests) and our reviewers will be happy to help you get started.
10491048

1050-
It is also appreciated when you [report an issue](https://code.shin.company/defer.js/issues/new/choose) or [open a discussion](https://code.shin.company/defer.js/discussions/new).
1049+
Don't feel confident contributing code? No problem! Improving the documentation, [reporting issues](https://code.shin.company/defer.js/issues/new/choose), and [starting discussions](https://code.shin.company/defer.js/discussions/new) are all valuable contributions that we appreciate.
10511050

1052-
Not ready to contribute code, but see something that needs work? From contributing to source code to improving the readability of the documentation, all suggestions are welcome!
1053-
1054-
> [NEED HELP] Please help me improve the documentation and examples.
1051+
> [NEED HELP] Let's make the documentation and examples better together!
10551052
10561053
* * *
10571054

1058-
## Support my activities
1055+
## Support the Project
10591056

1060-
If you like this repository, please [become a stargazer](https://code.shin.company/defer.js/stargazers) on my GitHub or join Gitter to follow further updates.
1057+
Love the project? Show your support by [becoming a stargazer](https://code.shin.company/defer.js/stargazers) on GitHub, joining our Gitter community, or sponsoring the project.
10611058

1062-
I also love to have your help, please consider [buying me a coffee](https://www.paypal.me/shinsenter), or sponsoring my work so I can create more helpful pieces of stuff 😉.
1059+
Consider [buying the developer a coffee](https://www.paypal.me/shinsenter) or [becoming a sponsor](https://www.patreon.com/appseeds) to help fund future development.
10631060

10641061
[![Donate via PayPal](https://img.shields.io/badge/Donate-Paypal-blue)](https://www.paypal.me/shinsenter) [![Become a sponsor](https://img.shields.io/badge/Donate-Patreon-orange)](https://www.patreon.com/appseeds)
10651062

1066-
I appreciate your love and support.
1063+
Your support is greatly appreciated.
1064+
10671065

10681066
* * *
10691067

demo/demo.css

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ h3,
2525
h4,
2626
h5,
2727
h6,
28-
p{
28+
p {
2929
margin: 0;
3030
padding: 0;
3131
font-weight: normal;
@@ -80,6 +80,11 @@ picture {
8080
display: inline-block;
8181
}
8282

83+
div>img,
84+
div>picture {
85+
margin: 0.5em;
86+
}
87+
8388
video,
8489
iframe {
8590
background-color: #000;
@@ -148,7 +153,7 @@ pre::before {
148153
content: "Code:";
149154
}
150155

151-
section > .helper::before {
156+
section>.helper::before {
152157
content: "Description:";
153158
}
154159

0 commit comments

Comments
 (0)