Follow the below to improve the client side scripting performance
1. Latest version of Jquery core Library
2. ID and element selectors are the fastest, since they are native DOM operations
$('#elementId')
3. Class selectors are slower than Id Selectors
$('.elementClass')
4. Pseudo Selector - powerful but slowest since it will call for all applicable selectors - $(':visible, :hidden');
5. Attribute Selector - slowest - $('[attribute=value]');
6. $parent.find('.child').show() - fastest
7. Use Jquery only in the needed place.
eg:
javascript: this.id; (short and effective way )
jquery: $(this).attr('id'); (js equalent is this.getAttribute('id'))
8. chaining
$('#elementId').removeClass('white').addClass('red').show();
(chaining is fastest followed by cached separate calls)
9. caching will decrease repeat selections
10. native JS for loop is better than $.each()
1. Latest version of Jquery core Library
2. ID and element selectors are the fastest, since they are native DOM operations
$('#elementId')
3. Class selectors are slower than Id Selectors
$('.elementClass')
4. Pseudo Selector - powerful but slowest since it will call for all applicable selectors - $(':visible, :hidden');
5. Attribute Selector - slowest - $('[attribute=value]');
6. $parent.find('.child').show() - fastest
7. Use Jquery only in the needed place.
eg:
javascript: this.id; (short and effective way )
jquery: $(this).attr('id'); (js equalent is this.getAttribute('id'))
8. chaining
$('#elementId').removeClass('white').addClass('red').show();
(chaining is fastest followed by cached separate calls)
9. caching will decrease repeat selections
10. native JS for loop is better than $.each()
No comments:
Post a Comment