JS/CSS module LazyLoad 3

Source: Internet
Author: User

Before starting this article, there are two minor issues to be noted.
Scenario 1
1
LazyLoad. js ([a. js, a. js], function (){});
Someone may ask why I want to introduce a. js twice on the page? I also want to ask. It is actually redundant. But some people like this. What should we do. It can only be cold. I can remove duplicate elements from the array internally. But this undoubtedly increases the amount of LazyLoad. js code, or I prefer not to write it like this. Of course, I certainly won't write it myself.
Case 2
1
LazyLoad. js ([a. js], function (){});
2
LazyLoad. js ([B. js], function (){});
This writing method is also put an end to it. It is equivalent
1
LazyLoad. js ([a. js, B. js], function (){});
Someone may want to have a callback after each js load. This function will be dedicated later. The premise of this series is that all js loads are called back, that is, only one callback after all resources are loaded.

Well, if you agree with the above Agreement, please proceed.
The first two articles completed the JavaScript and css inert loading functions, but there are still some problems. The most important thing is to load duplicate resources. This article will record the loaded resources (JS/CSS). If the record is repeated for the second load, the following prompt will be displayed:

The html is as follows:
01
<! Doctype html>
02
<Html>
03
<Head>
04
<Meta charset = "UTF-8">
05
<Title> LazyLoad_0.3.js </title>
06
<Script src ="Http://files.cnblogs.com/snandy/LazyLoad_0.3.js> </script>
07
<Script type = "text/javascript">
08
Var ary = [
09
Http://files.cnblogs.com/snandy/a.js,
10
Http://files.cnblogs.com/snandy/ B .js,
11
Http://files.cnblogs.com/snandy/c.js
12
];
13
LazyLoad. js (ary, function (){
14
C ();
15
});
16
Function clk (){
17
LazyLoad. js ([http://files.cnblogs.com/snandy/a.js], function (){
18
Alert (B );
19
});
20
}
21
</Script>
22
</Head>
23
<Body>
24
<Button onclick = "clk ()"> loading a. js again </button>
25
</Body>
26
</Html>
After the page is opened, three JavaScript codes a, B, and c are loaded. Click "loading a. js again" and a dialog box is displayed.

As you can see from Firebug, a. js is not loaded repeatedly.

However, if LazyLoad_0.2.js is introduced to the html file in the previous article, you will find that a. js is loaded again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.