Tuesday, August 02, 2011

How to Improve the speed of the aspx page?

Posted by Rahul Kharde at 1:30 AM
Recently, I developed a web application which calls many services and loads a lot of data in every page with a lot of calculation in the background from the database, so the site became slower. Then, I started searching Google to find out a good solution, and got some real good ideas to improve my web application's performance. Here, in this article, I am sharing the tips I applied in the application to improve its performance, and it really works fine now.
Web Application
1. Use Server.Transfer instead of Response.Redirect.
2. Set debug=false under compilation as follows:
< compilation debug="false">
3. Always check Page.IsValid when using Validator Controls
4. Use Foreach loop instead of For loop for String Iteration.
5. Use Finally Method to kill resources
The finally method gets executed independent of the outcome of the Block.
Always use the finally block to kill resources like closing database connection, closing files and other resources such that they get executed independent of whether the code worked in Try or went to Catch.
6. Use Client-Side Validation. (but not all the time you have to validate even on the server side)
7. Use Client Side Scripts for validations: Client site validation can help reduce round trips that are required to process user's request. In ASP.NET, you can also use client side controls to validate user input. However, do a check at the Server side too to avoid the infamous JavaScript disabled scenarios.
8. Check “Page.IsPostBack”. To avoid repetition code execution
9. GIF and PNG are similar, but PNG typically produces a lower file size. (True, but some browsers not supporting PNG format)
10. Disable ViewState when not required.
11. Turn off Tracing unless until required. (by default it's off, use on the pages where it's required)
< trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>
12. Turn off Session State, if not required.
< sessionstate timeout="20" cookieless="false" mode="Off" stateconnectionstring="tcpip=127.0.0.1:42424" sqlconnectionstring="data source=127.0.0.1;Trusted_Connection=no" >
13. Select the Release mode before making the final Build for your application.
14. Avoid Recursive Functions / Nested Loops
15. Avoid frequent round trips to the Database.
16. Use Caching to improve the performance of your application.
17. Reduce cookie size
18. Use strString=string.Empty instead of strString=""
19. Code optimization: Avoid using code like x = x +1; it is always better to use x+=1.
20. Data Access Techniques: DataReaders provide a fast and efficient method of data retrieval. DataReader is much faster than DataSets as far as performance is concerned
21. Use Finally Method to kill resources.
22. Validate all Input received from the Users.
23. Avoid Exceptions: Use If condition (if it is check proper condition)
24. When you can, use toString() instead of format(). In most cases, it will provide you with the functionality you need, with much less overhead.
25. Use short ID name for WebControl.
26. Use Repeater control instead of DataGrid , DataList, Because It is efficient, customizable, and programmable.
27. Never use object value directly; first get object value in local variable and then use. It takes more time then variable reading.
28. Don't make the member variables public or protected, try to keep private and use public/protected as properties.
29. Make your page files as light as possible. That is try to avoid unnecessary markups, e.g. use div elements instead of tables.
30. Write static messages in div and make it visible when necessary. This is faster than letting server set Text property of your label or div.
31. As always, avoid session variables because each ASP page runs in a different thread and session calls will be serialized one by one. So, this will slow down the application. Instead of session variables you can use the QueryString collection or hidden variables in the form which holds the values.
32. Enabling buffering will improve the performance, like
<% response.buffer=true %>
Then use:
<% response.flush=true %>
Database
1.    Return Multiple Resultsets at same time
2.    Use SqlDataReader Instead of Dataset wherever it is possible
3.    Avoid Unnecessary round trips
4.    Don't open many connections
5.    Use Stored Procedures Whenever Possible
6.    Avoid Auto-Generated Commands
Style sheet
1.    Compress CSS, JavaScript and Images
2.    Avoid Inline JavaScript and CSS
3.    Use early binding in Visual Basic or JScript code
4.    Place StyleSheets into the Header
5.    Use single css file instead of multiple css file.
Try your best to combine all your CSS based classes into a single .css file as lot of .css files will cause a large amount of requests, regardless of the file sizes.
css files are normally cached by browsers, so a single and heavy .css file doesn’t cause a long wait on each page request.
Inline .css classes could make HTML heavy, so again: go ahead with a single.css file.



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top