The method of dynamically loading JS to improve the opening speed of Web page _javascript skills

Source: Internet
Author: User

In general, if you load all the required JavaScript code at once, it will cause the initial page to open slowly, but many of the loaded code does not need to use, this wasteful performance waste should be avoided. If you want to dynamically load JavaScript code, you can use the DOM model to add <script> nodes to the HTML document and set the SRC attribute of the node (that is, the external JavaScript file) to the JavaScript code that needs to be loaded dynamically.

Here is an example of completing this feature:

(1), new jsloadertest.html file


JavaScript document 
function SayHello () { 
  alert ("Hello world! successfully loaded JavaScript file");   
} 
JavaScript document
function SayHello () {
  alert ("Hello world! successfully loaded JavaScript file");  
}

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.