Optimize JavaScript execution Speed _javascript tips

Source: Internet
Author: User
Tags bulk insert
1: Modify how the loop executes

for (Var i=0;i<element.childnodes.length;i++) {
Executing code
}
This method takes a Element.childNodes.length value for Each loop, and should be changed to the following
var n=element.childnodes.length
for (Var i=0;i<n;i++) {
Executing code
}

2: The number of times the DOM operation was modified
Dom to BULK insert a batch of similar nodes first construct an object and insert a
For example, the following method is reasonable:
var div=document.createelement ("div");
for (var i=0;i<10;i++) [

var element=document.createelement ("a");
A.href= "";
Div.appendchild (Element);

}
After you build the object, insert it once
Document.body.appendChild (DIV);
3: Reduce the reference level of the object, you can reduce the complexity of the browser to resolve the object

For example, a method is net. Loader.loadxml (params)
You don't have to use it every time.
var loadxml=net. Loader.loadxml;
Loadxml (params);
Related Article

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.