Skip to main content

How to Improve the speed of the aspx page?

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.

Comments

Popular posts from this blog

Connected and disconnected architecture in ADO.Net with Example

Connected Architecture of ADO.NET The architecture of ADO.net, in which connection must be opened to access the data retrieved from database is called as connected architecture. Connected architecture was built on the classes connection, command, datareader and transaction.  Connected architecture is when you constantly make trips to the database for any CRUD (Create, Read, Update and Delete) operation you wish to do. This creates more traffic to the database but is normally much faster as you should be doing smaller transactions. Disconnected Architecture in ADO.NET The architecture of ADO.net in which data retrieved from database can be accessed even when connection to database was closed is called as disconnected architecture. Disconnected architecture of ADO.net was built on classes connection, dataadapter, commandbuilder and dataset and dataview. Disconnected architecture is a method of retrieving a recor

HTTPHandler and HTTPModule in ASP.NET

If you want to implement pre-processing logic before a request hits the IIS resources. For instance you would like to apply security mechanism, URL rewriting, filter something in the request, etc. ASP.NET has provided two types of interception HttpModule and HttpHandler .   The web server examines the file name extension of the requested file, and determines which ISAPI extension should handle the request. Then the request is passed to the appropriate ISAPI extension.  For Example When an .aspx page is requested it is passed to ASP.Net page handler. Then Application domain is created and after that different ASP.Net objects like Httpcontext, HttpRequest, HttpResponse. HTTPModule: -    It's just like a filter. The Modules are called before and after the handler executes . -    HTTP Modules are objects which also participate the pipeline but they work before and after the HTTP Handler does its job, and produce additional services within the pipeline -  

ASP.NET Page Life Cycle with example

In this article, we are going to discuss the different methods and order they are executed during the load of an .aspx web page. Methods Description Page_PreInit Before page Initialization Page_Init Page Initialization LoadViewState View State Loading LoadPostData Postback Data Processing Page_Load Page Loading RaisePostDataChangedEvent PostBack Change Notification RaisePostBackEvent PostBack Event Handling Page_PreRender Page Pre Rendering Phase SaveViewState View State Saving Page_Render Page Rendering Page_Unload Page Unloading PreInit : The entry point of the page life cycle is the pre-initialization phase called “PreInit”. You can dynamically set the values of master pages and themes in this event. You can also dynamically create controls in this event.  Init : This event fires after each control h