Tuesday, December 28, 2010

Besty Johnson Diaper Bags

jQuery code optimize


jQuery code optimize

jQuery JavaScript Framework is a very practical, easy to use and which is also pretty fast. Since version 1.3, the selectors have also become faster again many times. Nevertheless, it is, especially for larger projects that never runs the JavaScript code to optimize. But I have some simple tips that help reduce the execution time of Java scripts to.
your traditional browser functions are always faster than functions in a Library
For example, one should rather normal for () use of JavaScript as the jQuery function $. Each () even if it delivers more features. Likewise, care should be taken to ensure that as few functions are used. So the first one to assemble the entire string, and only then the string in the location in the DOM fits to which he belongs. make
No long string concatenations, join instead use the easy navigation array
 var tmp =''; 
for (var i = 0; i \u0026lt;= rows.length; i + +) {tmp + =
'
' + alert rows [i ]+'';
}
(tmp);

/ / is faster
var tmp = [];
for (var i = 1; i \u0026lt;= rows.length; i + +) {
tmp [i] = '
' + rows [i-1] + ' ';} $

alert (tmp.join (''));
Easier DOM selectors to smaller parts are used faster
The fastest of the Selector is $ (' # id '). Whenever possible, you should each element of which is to be addressed and put a unique ID to address the item above. This is definitely the fastest way to address an item. The second fastest is, DASD selector $ ('tag') via an HTML tag. Even combined, these two are very fast.
 var range = $ ('# container'); 
var link = bereich.find ('a');
var table = bereich.find ('table');

0 comments:

Post a Comment