Skip to main content

Asp.net page Performance Improvement

ASP.NET Website Performance Improvement

In this article I will be explaining some quick, easy and must use Asp.net website Performance Improvement tips.

Asp.net Performance Improvement checklist is divided into 4 broad categories:
  1.  Identifying which part of asp.net web application requires optimization.
  2. Optimizing Asp.net web project to improve website performance
  3. Tips for writing codes in order to enhance performance.
  4. Database Optimization to improve performance (I will be explaining with regards to SQL Server but the same tips also apply to MySQL, Oracle or any other DB by changing syntactical meaning respectively.)
I will be discussing each asp.net performance improvement categories in detail.
Identifying which part of asp.net web application requires optimization
It is very important to identify which part of your application requires more attention in order to improve website performance.
1.      Using VS.Net 2010 Profiler
2.      Tracing asp.net web application
3.      Extension (Firefox Firebug, YSlow, Google Chrome Speed Tracer, IE9 Developer Tools)
4.      Monitoring tools like fiddler is also helpful.
Optimizing Asp.net web project to improve website performance
In order to improve asp.net web page performance, the most important aspect to consider is
  • Reducing asp.net page size - By reducing the page size it will get downloaded quickly and thus load quickly on the user's browser.  It will also reduce the bandwidth consumption of the website.  
  • Reduce number of HTTP requests -  It is very important to reduce the  number of HTTP requests on your server, it will help in reducing the server load and allowing more visitors to access your website.
  • Avoid round trip to server
In order to reduce asp.net page size
Avoid viewstate
Viewstate is used to maintain data of the web page on page postback. This increases page size.  I always prefer to turn off viewstate at page level and only turn on viewstate to specific control whose data I need to persist over page postback.
You can do so by <%@ Page  EnableViewState="false" %>
Situation in which you must avoid viewstate.
  • Only page which takes user input or control whose values you want to persist on page postback will require viewstate.  Example: If the user clicks on the submit button and if there are errors on the page you should persist user input, therefore in that case you should make EnableViewState="true" for those control or may be at page level.
  • Display pages or asp.net page that does not require page postback.  Example: Page on which you want to display the customer’s information in the datagrid, does not require viewstate therefore in this situation you can turn off viewstate.
Use div instead of table
Make use of div and css to replace table.  Combination of div and css is much faster than table.
Avoid big name for asp.net server control and CSS class tag
Do not give big name for ID fields of asp.net server control, especially to Content Place Holder asp.net server control in master page.  Content Place Holder ID name is appended to each asp.net server control inside the child page, so if you choose a big name for your asp.net server control, it will increase html file size.
Similarly if you choose a big name for CSS class tag, it will have long names and on every instance you make you need to use that class tag and in return this will increase the html size.
For this reason, I prefer to choose very short names for any control or css tag definition.
Example: <asp:ContentPlaceHolder ID="CC" runat="server">
Remove unnecessary white space (Compress generated HTML Size)
  • Remove white spaces between tags and lines of html render by asp.net pages.  In order to remove white spaces dynamically on all pages, you should put "render" method inside the master page class file.
  • Remove unused tags from CSS file and also remove unused script from Javascript file.
  • Remove white spaces from CSS file while deploying on production server. Remember that comments and whitespace inside your CSS and Javascript file are not required for execution; removing them will speed up css rendering time and script execution time.  You can add this step to your deployment checklist. You can take advantage of online compress css tool and online javascript compress tool.
Make use of JQuery instead of Ajax Control toolkit. 
I have observed that JQuery can do the task with less code and light weight, while Ajax control toolkit is bulkier and increases page size.
Reduce number of HTTP request
With the help of Firebug, Firefox extension, you can find out how many resource requests are made by your asp.net web page.  It is very important to reduce the number of HTTP requests on your server; it will help in reducing the server load and allow more visitors to access your website.
1.      Make minimum use of Images.  Images are good for UI but can increase the size of the  web page and lead to too many http request.
2.     Combine multiple db request into single db request.  Find more details on How to avoid multiple database request to improve performance
3.     Combine 2 or more css file into 1 file, since most of modern browser do cache css file, it will take some more time for 1st request, but the other subsequent requests will be fast.  Combining multiple css file into 1 will reduce number of http request.
You can use minifier tools as well to give a boost to performance of application.
4.     Combine 2 or more javascript file into 1 file, since most modern browsers do cache javascript file, it takes some time for 1st request, but the other subsequent requests will be fast.  Combining multiple javascript file into one will reduce the number of http request.
You can use minifier tools as well to give a boost to performance of application.
5.      Special tips if your web application is using JQuery
  • Try to use Jquery from CDN (Content distribution network) link for google CDN http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
  • While adding JQuery try using min version (Example: jquery-1.6.2.min.js), which is of less file size, since space and line breaks are removed from that.  This will help in faster loading of file and also improves performance of web application.
  • Avoid too many third party jquery controls, rather make use of JQuery UI, which supports too many control within one js file.
Avoid round trip to server
In order to give users a lightning fast effect, it is important that you avoid round trip to server.  You can use:
  • Caching
  • JQuery Ajax

Comments

Popular posts from this blog

Top 10 ASP.NET Web API Interview Questions

What is ASP.NET Web API? ASP.NET Web API is a framework that simplifies building HTTP services for broader range of clients (including browsers as well as mobile devices) on top of .NET Framework. Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON strings, etc. with many other advantages including: Create resource-oriented services using the full features of HTTP Exposing services to a variety of clients easily like browsers or mobile devices, etc. What are the Advantages of Using ASP.NET Web API? Using ASP.NET Web API has a number of advantages, but core of the advantages are: It works the HTTP way using standard HTTP verbs like  GET ,  POST ,  PUT ,  DELETE , etc. for all CRUD operations Complete support for routing Response generated in JSON or XML format using  MediaTypeFormatter It has the ability to be hosted in IIS as well as self-host outside of IIS Supports Model binding and Validation Support for OD...

Extension methods in C#

Consider the class C# 1 2 3 4 5 6 7 8 9 10 11 12 13          namespace ExtensionMethod      {          public class testClass {              public string sayHello ( ) {              return "Hello" ;            }        }      }     Invoke the above from your form using C# 1 2 3 4 5 6          testClass test = new testClass ( ) ;      MessageBox . Show ( test . sayHello ( ) ) ;     This will show “Hello” in message box. Consider the scenario where you don...

What is cookie? Advantages and disadvantages of cookies?

What is cookie? A cookie is a small piece of text file stored on user's computer in the form of name-value pair. Cookies are used by websites to keep track of visitors e.g. to keep user information like username etc. If any web application using cookies, Server send cookies and client browser will store it. The browser then returns the cookie to the server at the next time the page is requested. The most common example of using a cookie is to store User information, User preferences, Password Remember Option etc.It is also one of the common and mostly asked interview questions. Some facts about Cookie Here are a few facts to know about cookies: · Cookies are domain specific i.e. a domain cannot read or write to a cookie created by another domain. This is done by the browser for security purpose. · Cookies are browser specific. Each browser stores the cookies in a different location. The cookies are browser specific and so a cookie created in one browser(e.g in Google Chrome...