Dynamically load scripts to improve javascript Performance

Source: Internet
Author: User

Dynamically load scripts to improve javascript Performance

Dynamic Loading of scripts can effectively improve javascript performance. The following is a good example.

With the Document Object Model (DOM), almost all content in HTML can be dynamically created using Javascript. Basically, the <script> tag is no different from other elements on the page: It can be referenced by DOM and can be moved, deleted, or even created in the document. Using the standard DOM method, you can easily create a New Year's <script> element:

The Code is as follows:

<Script type = "text/javascript">

Var script = document. createElement ("script ");

Script. type = "text/javascript ";

Script. src = "file1.js ";

Document. getElementByTagName ("head") [0]. appendChild (script );

</Script>

 

The newly created <script> element loads the file1.js file. The file starts to be downloaded when the element is added to the page. The focus of this technology is that the file download and execution process will not block other processes on the page at any time. You can even put the code in the

 

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.