Pages

Men

rh

6/18/2012

Improve the performance of Asp.net Page:


Improve the Asp.net Page performance:
  • Set debug=false under compilation as follows: <compilation default Language="c#" debug="false">
  • Use Server. Transfer instead of Response.Redirect.
  • Always check Page.IsValid when using Validator Controls
  • Use Foreach loop instead of For loop for String Iteration.
  • Use Client-Side Validation. (but not all the time you have to validate even on the server side)
  • Check “Page.IsPostBack”. To avoid repetition code execution.
  • GIF and PNG are similar, but PNG typically produces a lower file size. (True, but some browsers not supporting PNG format)
  • Use the AppOffline.htm when updating binaries
  • 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"/>
  • Precompiled pages and disable AutoEventWireup; setting the AutoEventWireup attribute to false in the Machine.config file.
  • 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">
  • Select the Release mode before making the final Build for your application.
  • This option is available in the Top Frame just under the Window Menu option. By default, the Mode is Debug
  • Disable ViewState when not required. 
  • EnableViewState="false"
  • Avoid frequent round trips to the Database.
  • Use Caching to improve the performance of your application.
  • Validate all Input received from the Users.
  • Use Finally Method to kill resources. (But not in the case of using
  • The String and Stringbuilder Magic.
  • It is nice to use Stringbuilder instead of String when string are Amended. Strings occupy different memory location in every time of amended where stringbuilder use single memory location
  • Never use object value directly; first get object value in local variable and then use. It takes more time then variable reading.
  • Avoid Exceptions: Use If condition (if it is check proper condition)
  • Code optimization:  Avoid using code like x = x +1; it is always better to use x+=1.
  • 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
  • Before doing a bulky ASP code processing, you can check to make sure Response.IsClientConnected.
  • 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.
  • Enabling buffering will improve the performance, like
  • <% response.buffer=true %>
  • Then use:
  • <% response.flush=true %> 
  • Use Repeater control instead of DataGrid , DataList, Because It is efficient, customizable, and programmable.
  • Data listing is more time consume when large data are retrieve from database. Paging will display only particular data but take load of all data.
  • Fetch only data that is needed for current page.
  • Avoid Inline JavaScript and CSS
  • 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.
  • Reduce cookie size 
  • Compress CSS, JavaScript and Images
  • Usage of "using" and I don't know why it's not yet published.
  • Don't make the member variables public or proteted, try to keep private and use public/protected as properties.
  • Use strString=string.Empty instead of strString="" . [And perhaps instead of strString=null also (?)]
  • Make your page files as light as possible. That is try to avoid unnecessary markups, e.g. use div elements instead of tables.
  • 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.
  • Retrieve data from database at once, if possible. Don't add up to database trip as far as possible. For this, combine the datafields from different tables and select them.
  • Use short ID name for WebControl.

No comments :

Post a Comment