High-performance read javaScript

1.HTML script can block other resources page to download, all the <script> tag into the bottom of the <body> tag as possible.

2. The first global variables stored in a local variable, global variable in a local variable instead to reduce the impact on performance.

3. The variable position deeper scope longer access time, local variables present in the starting position of the fastest access speed scope chain, in the most global variables scope chain ends, access to the slowest.

4. nested objects can significantly affect performance.

The cycle performance optimization

(1) reduce or simplify the iterative process of each transaction, or to reduce the number of iterations

for ( var I = 0, len = item.length; I <len; I ++ ) 
{ 
    Process (Item [I]); 
} 
// modify 
var J = 0, COUNT = item.length;
 the while (J < COUNT) 
{ 
    Process (Item [J ++ ]) 
} 
// length lookup properties once before the circulation operation after rewriting, local variables directly read control condition read faster, most browsers can save 25% uptime. 

// re-optimized 
var J = item.length;
 the while (J, ) 
{ 
    Process (Item [J]) 
} 
// control condition and simply compare until 0 is 0 (equivalent to false) control condition is reduced from two to further improve the cycle time speed (running upgrade 50%)

6. A large number determination condition, instead of using the switch if-esle

// if judged optimized 
IF
(value == 0 ) { return result0; } the else IF (value ==. 1 ) { return RESULT1; } .................... ..... the else IF (value == 10 ) { return result10; } // this expression is determined up to 10 times, and then if the value uniformly distributed between 0 and 10 will increase the run time, the code rewritten as: IF (value <. 6 ) { IF (value <. 3 ) { ...... } the else { ..... } } the else { ..... } // use the dichotomy range into the series range, after rewriting a maximum of four times and judgment to find out

 7. stitching concat character than the (symbol) + slow efficiency

 

 

 

 

 

 

 

 

 

                                                                - reduce the workload is the best performance optimization

Guess you like

Origin www.cnblogs.com/xyptechnology/p/11115379.html