Home > Web Front-end > JS Tutorial > Optimize the execution speed of javascript_javascript tips

Optimize the execution speed of javascript_javascript tips

WBOY
Release: 2016-05-16 18:35:55
Original
1133 people have browsed it

1: Modify the execution method of the loop

for(var i=0;iExecution code
}
In this way, the value of element.childNodes.length must be taken every time it loops. It should be changed to the following
var n=element.childNodes.length
for(var i=0;iExecution code
}

2: Modify the number of dom operations
Instead of inserting a batch of similar nodes into the dom in batches, it is better to construct an object first and insert it once
For example, the following method is reasonable:
var div=document.createElement("div") ;
for(var i=0;i
var element=document.createElement("a");
a.href="";
div .appendChild(element);

}
//After constructing the object, insert it once
document.body.appendChild(div);
3: Reduce the reference level of the object, which can reduce browsing The complexity of object parsing by the processor

For example, a method is net.Loader.LoadXml(params)
You don’t have to use it every time, you can
var loadXml=net.Loader.LoadXml;
loadXml(params);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template