1: Modify the execution method of the loop
for(var i=0;i
}
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;i
}
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);