Source: msdn [English Original] msdn.microsoft.com/library/en-us/dnwebgen/html/dhtmlperf.asp?frame=true ["中文 = ["] www.microsoft.com/chna/msdn/msdnonline/features /DHTMLPERF.ASP1. Try to use the same script function to change the HTML content. If there are multiple events triggered, try only to change the same place. 2. Try to focus on the content. If you don't have the content of HTML, try to use InnerText instead of innerhtmlslow: divupdate.innerhtml = ""; for (var i = 0; i <100; i ) {divupdate.innerhtml = " this is a slow Method ! Span> ";} fast: var str =" "; for (var i = 0; i <100; i ) {str =" this is faster Because IT Uses A String! Span> "} divupdate.innerhtml = str; 3. Try to use Innertext instead of DOM when updating text content
Slow:
Var node; for (var i = 0; i <100; i ) {node = document.createElement ("span"); Node.createTextNode ("Using CreateTextNode ()); DivuPdate.Appendchild (Node }
FAST:
Var node; for (var i = 0; i <100; i ) {node = document.createElement ("span"); node.innertext = "using innerText Property"; DivUpdate.Appendchild (node);}
4. Try to use CreateElement and InsertAdjacentelement methods, not InsertJacenthtml
Slow:
For (var i = 0; i <100; i ) {divupdate.insertadjacenthtml ("beforeend", " uses insertjacenthtml () span>");}
FAST:
Var node; for (var i = 0; i <100; i ) {node = document.createElement ("span"); node.innertext = "Uses insertjacentelement ()"; DivUpdate.insertAdjacentelement ("beforeend", node); }
5. With the huge case, try to use InnerHTML to add items.
Slow:
Var Opt; divupdate.innerhtml = "
Var str = "
FASTER:
Var arr = new array (1000); for (var i = 0; i <1000; i ) {arr [i] = "
6. Use the DOM to create a table than Tom (Insertrow, Insertcell)
Slow:
Var row; var cell; for (VAR i = 0; i <100; i ) {row = tblupdate.inSertrow (); for (var j = 0; j <10; j ) {cell = row.insertcell (); Cell.innertext = "ROW" i ", Cell" J;}}
FAST:
Var Row; var cell; var tbody = tblupdate.childNodes [0]; tblupdate.Appendchild (TBODY); for (var i = 0; i <100; i ) {row = document.createElement ("tr"); tbody. Appendchild (row); for (var j = 0; j <10; j ) {cell = document.createElement ("td"); row.Appendchild (Cell); cell.innerText = "ROW" i ", Cell J;}}
7. General operation, try to place it in a separate external script file
8. Constraint your dynamic properties (refer to the usage of setExpression)
9. Use data binding to display your information, you can use sort, filtering, etc. to provide different views, but only need to access a server (reducing the problem of frequent access server)
10. Do not add custom properties to the Document object, which makes additional rejuvenation each time you read this property. Recommended to add Slow on the Window object:
For (var i = 0; i <1000; i ) {var tmp; window.document.myproperty = "item" i; tmp = window.document.myproperty;}
FAST:
For (var i = 0; i <1000; i ) {var TMP; window.myproperty = "item" i; tmp = window.myproperty;
11. Try to use the Style object directly to change the appearance of the HTML object, not the classname or Stylesheet object associated with Clas.
12. When accessing the parent object of the TextRange object (referring to the return value of the Parentelement method), first collapse merge RANGE, especially complex Range
13. Insert the object first, then add its content
Slow
(1) .CREATE
(2) .create
(3) CREATE TEXTNODE
(4) INSERT TEXTNODE INTO
As mentioned earlier, here will use InnerText faster
(5) INSERT
(6) INSERT
FAST
(1) CREATE
(2) CREATE
(3) CREATE TEXTNODE
As mentioned earlier, here will use InnerText faster
(4) INSERT
(5) INSERT
(6) INSERT TEXTNODE INTO
As mentioned earlier, here will use InnerText faster
14. With POSLEFT, POSTOP, POSWIDTH, POSHEIGHT instead of Left, TOP, etc., reduce strings -> value conversion
15. Use the timer (refer to settimeout, setInterval as possible), and operate all the objects to be changed in the same timer