Several methods of delaying the loading of JS code speed up the access speed of Web pages _javascript skills

Source: Internet
Author: User

This article describes how to delay the loading of JavaScript code and speed up access to your Web pages.

When a site has a lot of JS code to load, JS code placed in a certain degree will image the loading speed of the Web page, in order to let our web page loading faster, this article summed up a few points of attention:
1. Delay Loading JS Code

Copy Code code as follows:

<script type= "Text/javascript" src= "id=" my "></script>
<script type= "Text/javascript" >
SetTimeout ("document.getElementById (' my '). src= ' include/php100.php ';", 3000);/delay 3 seconds
</script>

This way by delaying loading JS code, to allow more time to load the page!

2, JS final load scheme a
Insert the following code where you want to insert JS:
Program code
Copy Code code as follows:

<span id= "L4ever" >LOADING...</span>

Of course, that loading ... You can switch to your favorite small picture. It looks like an Ajax effect.
Then insert at the bottom of the page:
Program code
Copy Code code as follows:

<span id= "Ad_l4ever" > Your JS code is here!</span >
<script>L4EVER.innerHTML=AD_L4EVER.innerHTML; Ad_l4ever.innerhtml= "";</script>

3, let JS final load scheme two
This involves the loading sequence of the page, such as the introduction of external JS script file, if placed in the head of the HTML, the page before loading the JS script will be loaded into the page, and into the body, will be in accordance with the page down from the loading sequence to run JavaScript code ~ ~ ~ So we can put JS outside the introduction of the file to the bottom of the page, to let JS finally introduced, thus speeding up the page load speed.

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.