Skip to content

Commit

Permalink
Merge pull request #83 from shinsenter/develop
Browse files Browse the repository at this point in the history
Reduced library size
  • Loading branch information
shinsenter committed Apr 3, 2021
2 parents c8e9ba5 + fc21f7b commit dc02899
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 33 deletions.
1 change: 0 additions & 1 deletion .build/.uglifyjs
Expand Up @@ -6,7 +6,6 @@
"reserved": [],
"toplevel": false
},
"nameCache": {},
"output": {
"ascii_only": true,
"beautify": false,
Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -16,7 +16,7 @@
[![NPM](https://nodei.co/npm/@shinsenter/defer.js.png?downloads=true)](https://www.npmjs.com/package/@shinsenter/defer.js)

- **Package**: [@shinsenter/defer.js](https://www.npmjs.com/package/@shinsenter/defer.js)
- **Version**: 2.3.0
- **Version**: 2.4.0
- **Author**: Mai Nhut Tan <shin@shin.company>
- **Copyright**: 2021 AppSeeds <https://code.shin.company/>
- **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE)
Expand Down Expand Up @@ -90,7 +90,7 @@ or load it from a CDN like below example.
<title>My Awesome Page</title>

<!-- Put defer.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer.min.js"></script>

<!-- To support older browsers such as Internet Explorer 9 -->
<!-- You may want to put IntersectionObserver polyfill right after defer.min.js tag -->
Expand All @@ -111,7 +111,7 @@ instead of `defer.min.js`.

```html
<!-- Put defer_plus.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer_plus.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer_plus.min.js"></script>

<!-- To support older browsers such as Internet Explorer 9 -->
<!-- You may want to put IntersectionObserver polyfill right after defer.min.js tag -->
Expand Down Expand Up @@ -345,7 +345,7 @@ you should load `IntersectionObserver` polyfill library
right after the `defer.min.js` script tag as following example:
```html
<!-- Put defer.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer.min.js"></script>

<!-- Put polyfill right after defer.min.js tag -->
<script>'IntersectionObserver'in window||document.write('<script src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"><\/script>');</script>
Expand Down
2 changes: 1 addition & 1 deletion dist/defer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/defer_plus.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/about.md
Expand Up @@ -16,7 +16,7 @@
[![NPM](https://nodei.co/npm/@shinsenter/defer.js.png?downloads=true)](https://www.npmjs.com/package/@shinsenter/defer.js)

- **Package**: [@shinsenter/defer.js](https://www.npmjs.com/package/@shinsenter/defer.js)
- **Version**: 2.3.0
- **Version**: 2.4.0
- **Author**: Mai Nhut Tan <shin@shin.company>
- **Copyright**: 2021 AppSeeds <https://code.shin.company/>
- **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE)
Expand Down Expand Up @@ -90,7 +90,7 @@ or load it from a CDN like below example.
<title>My Awesome Page</title>

<!-- Put defer.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer.min.js"></script>

<!-- To support older browsers such as Internet Explorer 9 -->
<!-- You may want to put IntersectionObserver polyfill right after defer.min.js tag -->
Expand All @@ -111,7 +111,7 @@ instead of `defer.min.js`.

```html
<!-- Put defer_plus.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer_plus.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer_plus.min.js"></script>

<!-- To support older browsers such as Internet Explorer 9 -->
<!-- You may want to put IntersectionObserver polyfill right after defer.min.js tag -->
Expand Down
2 changes: 1 addition & 1 deletion docs/apis.md
Expand Up @@ -207,7 +207,7 @@ you should load `IntersectionObserver` polyfill library
right after the `defer.min.js` script tag as following example:
```html
<!-- Put defer.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer.min.js"></script>

<!-- Put polyfill right after defer.min.js tag -->
<script>'IntersectionObserver'in window||document.write('<script src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"><\/script>');</script>
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Expand Up @@ -16,7 +16,7 @@
[![NPM](https://nodei.co/npm/@shinsenter/defer.js.png?downloads=true)](https://www.npmjs.com/package/@shinsenter/defer.js)

- **Package**: [@shinsenter/defer.js](https://www.npmjs.com/package/@shinsenter/defer.js)
- **Version**: 2.3.0
- **Version**: 2.4.0
- **Author**: Mai Nhut Tan <shin@shin.company>
- **Copyright**: 2021 AppSeeds <https://code.shin.company/>
- **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE)
Expand Down Expand Up @@ -90,7 +90,7 @@ or load it from a CDN like below example.
<title>My Awesome Page</title>

<!-- Put defer.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer.min.js"></script>

<!-- To support older browsers such as Internet Explorer 9 -->
<!-- You may want to put IntersectionObserver polyfill right after defer.min.js tag -->
Expand All @@ -111,7 +111,7 @@ instead of `defer.min.js`.

```html
<!-- Put defer_plus.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer_plus.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer_plus.min.js"></script>

<!-- To support older browsers such as Internet Explorer 9 -->
<!-- You may want to put IntersectionObserver polyfill right after defer.min.js tag -->
Expand Down Expand Up @@ -345,7 +345,7 @@ you should load `IntersectionObserver` polyfill library
right after the `defer.min.js` script tag as following example:
```html
<!-- Put defer.min.js here -->
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer.min.js"></script>

<!-- Put polyfill right after defer.min.js tag -->
<script>'IntersectionObserver'in window||document.write('<script src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"><\/script>');</script>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "@shinsenter/defer.js",
"title": "defer.js",
"version": "2.3.0",
"version": "2.4.0",
"description": "🥇 A super small, super efficient library that helps you lazy load almost everything like images, video, audio, iframes as well as stylesheets, and JavaScript.",
"homepage": "https://shinsenter.github.io/defer.js/",
"license": "MIT",
Expand Down
26 changes: 11 additions & 15 deletions src/defer.js
Expand Up @@ -117,17 +117,15 @@
return _toArray.call((parent || document).querySelectorAll(selector));
}

function _reveal(node, _attributes, _property, _found) {
for (_attributes = _propArray(node); _attributes[0];) {
_property = _attributes[_shift]();
_found = _dataRegExp.exec(_property.name);
function _reveal(node) {
_query('source', node)[_forEach](_reveal);
_propArray(node)[_forEach](function (_property, _found) {
_found = _dataRegExp.exec(_property.name);

if (_found) {
node[_setAttribute](_found[1], _property.value);
node[_found[1]] = _property.value;
}
}

_query('source', node)[_forEach](_reveal);
});

if (_load in node) {
node[_load]();
Expand All @@ -138,7 +136,7 @@
defer(function (_found) {
_found = _query(selector || _selectorDeferJs);

function _next(_node, _clone, _attributes, _property) {
function _next(_node, _clone) {
_node = _found[_shift]();

if (_node) {
Expand All @@ -148,13 +146,11 @@
// Clone the node
_clone = _newNode(_node.nodeName);
_clone.text = _node.text;
for (_attributes = _propArray(_node); _attributes[0];) {
_property = _attributes[_shift]();

_propArray(_node)[_forEach](function (_property) {
if (_property.name != 'type') {
_clone[_setAttribute](_property.name, _property.value);
_clone[_property.name] = _property.value;
}
}
});

// Execute the node
if (_clone.src && !_clone[_hasAttribute]('async')) {
Expand Down Expand Up @@ -390,7 +386,7 @@
* ```html
* <!-- Put defer.min.js here -->
* <script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer.min.js"></script>
* <script src="https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer.min.js"></script>
*
* <!-- Put polyfill right after defer.min.js tag -->
* <script>'IntersectionObserver'in window||document.write('<script src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"><\/script>');</script>
Expand Down

0 comments on commit dc02899

Please sign in to comment.