Tuesday, August 26, 2014

how to increase jquery performance in asp.net

1)       USE CDN
By taking advantage of the CDN, you can significantly improve the performance of your Ajax   applications. The contents of the CDN are cached on servers located around the world. In addition, the CDN enables browsers to reuse cached third party JavaScript files for web sites that are located in different domains. Google, Microsoft and  Jquery provide the CDN
2)      Use Ids instead of Class
It's much better to select objects by ID because of the library's behavior: jQuery uses the browser's native method, getElementByID(), to retrieve the object, resulting in a very fast query.
By class  traversing the whole DOM

In Asp.net we have  find  the control three ways
You can use a wild card CSS selector
The above line matches all HTML input elements with an ID attribute that ends with "TextBox". It will match:
$(document).ready(function () {
     //write your code here
     var  txt =$('input[id$=TextBox1]').val();
 
     var txt1= $('#' + '<%=TextBox1.ClientID %>').val(); //this is better 
 
    var txt2=$("[id$=_ TextBox1]").val();
 
 
 
});
In this example we have use find the control by id but Also realize that doing attribute selector searches are fairly slow (but then ‘slow’ is relative). If you have very large documents with lots of elements and you’re doing many look ups using this function, you may run into performance issues. 

3)      Use Latest Jquery  Version
jQuery is in constant development and improvement.  Jquery Team are always researching new ways to improve program performances. So We have to use the latest version
4)      Minify Scripts  and css
Browser are  not unable  to process more then one script concurrently  So they queue then up  And lots of script increase the   page load time. So Always use minified scipts  

5)      For And For each Loop
tested in my solution that the same block of code using for is most of the times faster than each. So means native function much faster as compared to helper function
so for loop is better
6)      Others
           Dom manipulation should be limited,
            Concatenation should be limited
            use  join comma separated list
  

No comments:

Post a Comment

http://blogsiteslist.com