|
5 | 5 | [](https://code.shin.company/defer.js/blob/master/LICENSE)
|
6 | 6 | [](https://snyk.io/advisor/npm-package/@shinsenter/defer.js)
|
7 | 7 | [](https://www.codefactor.io/repository/github/shinsenter/defer.js)
|
8 |
| - |
9 |
| -* * * |
10 |
| - |
11 | 8 | [](https://code.shin.company/defer.js/releases)
|
12 | 9 | [](https://code.shin.company/defer.js/releases)
|
13 | 10 | [](https://www.npmjs.com/package/@shinsenter/defer.js)
|
14 | 11 | [](https://www.jsdelivr.com/package/npm/@shinsenter/defer.js)
|
15 | 12 |
|
| 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 | + |
16 | 23 | [](https://www.npmjs.com/package/@shinsenter/defer.js)
|
17 | 24 |
|
18 | 25 | - **Package**: [@shinsenter/defer.js](https://www.npmjs.com/package/@shinsenter/defer.js)
|
19 |
| -- **Version**: 3.4.0 |
| 26 | +- **Version**: 3.5.0 |
20 | 27 | - **Author **: Mai Nhut Tan <[email protected]>
|
21 |
| -- **Copyright**: 2022 AppSeeds <https://code.shin.company/> |
| 28 | +- **Copyright**: 2019-2023 SHIN Company <https://code.shin.company/> |
22 | 29 | - **License**: [MIT](https://code.shin.company/defer.js/blob/master/LICENSE)
|
23 | 30 |
|
24 |
| -> [NEED HELP] Please help me improve the documentation and examples. I appreciate your love and support. |
| 31 | +--- |
25 | 32 |
|
26 |
| -* * * |
| 33 | +## Document in other languages |
27 | 34 |
|
| 35 | +> [NEED HELP] Let's make the documentation and examples better together! |
28 | 36 |
|
29 |
| -## Introduction |
| 37 | +### 日本語 |
30 | 38 |
|
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 | +日本人のはこちらの記事を参考にしていただければ幸いです。 |
34 | 40 |
|
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) |
37 | 44 |
|
38 |
| -You would be happy, and your customers would be happy, too. |
| 45 | +#### Credits |
39 | 46 |
|
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. |
41 | 48 |
|
| 49 | +*** |
42 | 50 |
|
43 |
| -## Why you should consider using Defer.js? |
| 51 | +## Why Choose Defer.js |
44 | 52 |
|
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 |
47 | 57 | - ⚡️ 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 |
54 | 61 |
|
| 62 | +<sup>*Legacy browsers like Internet Explorer 9 require `IntersectionObserver` polyfill.</sup> |
55 | 63 |
|
56 |
| -## Browser support |
| 64 | +## Browser Support |
57 | 65 |
|
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 |
63 | 68 | - 🖥 Firefox 4+
|
64 | 69 | - 🖥 Safari 3+
|
65 | 70 | - 🖥 Chrome
|
66 | 71 | - 🖥 Opera
|
67 | 72 | - 📱 Android 4+
|
68 | 73 | - 📱 iOS 3.2+
|
69 | 74 |
|
70 |
| - |
71 | 75 | ## Getting started
|
72 | 76 |
|
| 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 | + |
73 | 79 | ### Basic
|
74 | 80 |
|
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. |
76 | 82 |
|
77 | 83 | ```html
|
78 | 84 | <head>
|
79 | 85 | <meta charset="UTF-8" />
|
80 | 86 | <title>My Awesome Page</title>
|
81 | 87 |
|
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> |
84 | 90 |
|
85 | 91 | <!-- ... -->
|
86 | 92 | </head>
|
87 | 93 | ```
|
88 | 94 |
|
89 | 95 | ### Inlining the library
|
90 | 96 |
|
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. |
92 | 98 |
|
93 | 99 | ```html
|
94 | 100 | <head>
|
95 | 101 | <meta charset="UTF-8" />
|
96 | 102 | <title>My Awesome Page</title>
|
97 | 103 |
|
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> |
101 | 106 |
|
102 | 107 | <!-- ... -->
|
103 | 108 | </head>
|
104 | 109 | ```
|
105 | 110 |
|
106 | 111 | ### Compatibility with older versions
|
107 | 112 |
|
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`. |
110 | 114 |
|
111 | 115 | ```html
|
112 | 116 | <head>
|
113 | 117 | <meta charset="UTF-8" />
|
114 | 118 | <title>My Awesome Page</title>
|
115 | 119 |
|
116 | 120 | <!-- 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> |
118 | 122 |
|
119 | 123 | <!-- ... -->
|
120 | 124 | </head>
|
121 | 125 | ```
|
122 | 126 |
|
123 | 127 | ### For OLD browsers (such as IE9)
|
124 | 128 |
|
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. |
129 | 130 |
|
130 | 131 | ```html
|
131 |
| -<script>/* the content of defer.min.js */</script> |
| 132 | +<script>/* Defer.js content */</script> |
132 | 133 |
|
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> |
136 | 136 | ```
|
137 | 137 |
|
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. |
140 | 139 | ## Functions
|
141 | 140 |
|
142 | 141 | * [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.
|
678 | 677 | ```html
|
679 | 678 | <script>
|
680 | 679 | 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!'); |
682 | 681 | });
|
683 | 682 | </script>
|
684 | 683 | ```
|
@@ -817,7 +816,8 @@ AddThis add-on will not be loaded until the user starts interacting with the pag
|
817 | 816 | <div class="demo-addthis"></div>
|
818 | 817 |
|
819 | 818 | <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; |
821 | 821 | var loaded = false;
|
822 | 822 |
|
823 | 823 | Defer.js(fileUrl, 'addthis-js', 0, function() {
|
@@ -1040,30 +1040,28 @@ A [Function](#Function) receives a DOM [Node](#Node) object as its argument.
|
1040 | 1040 |
|
1041 | 1041 | ## Community
|
1042 | 1042 |
|
1043 |
| -As an open-source project, we'd appreciate any help and contributions! |
1044 |
| - |
1045 |
| -[](https://code.shin.company/defer.js/stargazers) [](https://code.shin.company/defer.js/discussions/new) [](https://gitter.im/shinsenter/defer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](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. |
1046 | 1044 |
|
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 | +[](https://code.shin.company/defer.js/stargazers) [](https://code.shin.company/defer.js/discussions/new) [](https://gitter.im/shinsenter/defer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://discord.com/channels/962919929307357234/1000635855712559165) |
1048 | 1046 |
|
| 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. |
1049 | 1048 |
|
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. |
1051 | 1050 |
|
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! |
1055 | 1052 |
|
1056 | 1053 | * * *
|
1057 | 1054 |
|
1058 |
| -## Support my activities |
| 1055 | +## Support the Project |
1059 | 1056 |
|
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. |
1061 | 1058 |
|
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. |
1063 | 1060 |
|
1064 | 1061 | [](https://www.paypal.me/shinsenter) [](https://www.patreon.com/appseeds)
|
1065 | 1062 |
|
1066 |
| -I appreciate your love and support. |
| 1063 | +Your support is greatly appreciated. |
| 1064 | + |
1067 | 1065 |
|
1068 | 1066 | * * *
|
1069 | 1067 |
|
|
0 commit comments