Page Optimization in Asp.Net

1. Use Caching - Cache Data whenever possible especially data which you are sure won't change at all or will be reused multiple times in the application. Make sure to have consistent cache keys to avoid any bugs. For simple pages which do not change regularly you can also go for page Caching
a. <% @OutputCache Duration="60" VaryByParam="none" %>

2. Use Script files - As a rule unless required do not insert JavaScript directly into any page, instead save them as script file ".js" and embed them. The benefit being that common code can be shared and also once a script file is loaded into browser cache, it is directly picked up from browser cache instead of downloading again.
3. Remove Unused Javascript - Run through all Javascript and make sure that all unused script is removed.
4. Remove Hidden HTML when using Tabstrip - In you are using a Tabstrip control and if the HTML size is too large and the page does frequent reloads, then turn Autopostback of Tabstrip on, put each Pageview inside a panel and turn visibility of all Panels except the current one to False. This will force the page to reload every time a tab is changed however the reload time will reduce heavily. Use your own jurisdiction to best use.
5. Disable session when not using it - If your page does not use session then disable session specifically for that page.
a. <%@ Page EnableSessionState="false" %>
b. If the page only reads session but does not write anything in session, then make it read only.
c. <%@ Page EnableSessionState="ReadOnly" %>
6. .Use Ajax - In performance critical application where there are frequent page loads, resort to Ajax.
7. Use the SqlDataReader class - The SqlDataReader class provides a means to read forward-only data stream retrieved from a SQL Server� database. If you only need to read data then SqlDataReader class offers higher performance than the DataSet class because SqlDataReader uses the Tabular Data Stream protocol to read data directly from a database connection
8. Use Stored Procedures - Stored procedures are pre-compiled and hence are much faster than a direct SQL statement call.
9. Paging in Database Side - When you needs to display large amount of Data to the user, go for a stored procedure based Data Paging technique instead of relying on the Data Grid/ Data List Paging functionality. Basically download only data for the current page.
10. Disable ViewState - Set "EnableViewState=false" for any control that does not need the view state. As a general rule if your page does not use postback, then it is usually safe to disable viewstate for the complete page itself.

Comments