Click here to Skip to main content
Click here to Skip to main content

ASP.NET Web Site Performance Improvement

By , 28 May 2009
 

Introduction

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.

Things I Have Done

1. HTTP Compression

HTTP compression is used to compress page content from the server end. It compress HTTP requests and responses, so is a great performance improvement. My project is hosted in Windows Server 2003, and I implemented HTTP compression after reading this article.

2. Disable Possible ViewState

View State allows the page state to be persisted with the client, and it does not require cookies or server memory. View State saves data in a hidden input filed inside a page. Definitely, it is a powerful feature, but the drawback is it increases page size and memory allocation in the server.

So, we should avoid View State where it is not necessary. Especially, in the case of DataGrid controls, we should avoid View State as it loads all the grid data in the page state.

In my application, I disabled View State for most of the controls and pages where View State is not necessary. THis made the page sizes smaller.

3. Changes in the Web.Config File

  1. Use page caching:
  2. This will save your page only for a certain amount of time, and the page will be faster to load. But, remember that if your page data changes frequently, it is not a good idea to use page caching.

    <caching>
    <outputCacheSettings>
        <outputCacheProfiles>
            <add name="cached" duration="600" 
                varyByParam="none" enabled="true"/>
        </outputCacheProfiles>
    </outputCacheSettings>
    </caching>
  3. Remove unnecessary httpModules from the web.config:
  4. <add name="ScriptModule" 
         type="System.Web.Handlers.ScriptModule, System.Web.Extensions, 
               Version=3.5.0.0, Culture=neutral, 
               PublicKeyToken=31BF3856AD364E35"/>
    <remove name="WindowsAuthentication" />
    <remove name="PassportAuthentication" />
    <remove name="AnonymousIdentification" />
    <remove name="UrlAuthorization" />
    <remove name="FileAuthorization" />
  5. Turn off trace:
  6. <trace enabled="false" pageOutput="false" />
  7. As I have used membership, I disabled automatic save for profiles:
  8. <profile enabled="true" automaticSaveEnabled="false" />
  9. Set debug=false:
  10. <compilation debug="false">

4. Implement Cache Dependency

Three types of cache dependencies are available:

  1. Caching Dependency on cached items
  2. Cache Dependency on a file
  3. Cache Dependency on SQL

For my project, I used cache dependency on file. For your project, you can choose to use a dependency based on which will be the best fit for your application. Here is a nice example of cache dependency on file.

5. Optimize Stylesheets

It is important to clean up style sheets and remove unnecessary code from style sheets because it increases the load time. Remove all unnecessary classes from style sheets and try to use a single CSS file. In my project, I have used a tool to reduce the size of my stylesheet. I used this service to reduce the size of my CSS file by 20%.

6. Optimize JavaScript

I optimize my JavaScript using this service.

7. JS and CSS File Position

According to the advice from some good articles, I put the CSS file declaration at the top of my master page. It is recommended to call CSS files at the top of a page because the page rendering will progressively become efficient.

I put JavaScript file links at the bottom of the main master file. If we put scripts at the top of the page, then it will cause unnecessarily high load times.

8. server.transfer() Instead of response.redirect()

Where possible, I use server.transfer() instead of response.redirect(). It loads pages faster because it posts only the form, not the complete page.

9. Client-side Script for Validation

For page validation, I use client-side validations instead of postbacks. This way, I reduce round trips in pages.

Points of Interest

There are many more things that can be done to improve the performance of a web application. Given below are the links of some very good articles:

History

  • 26th May, 2009: First version.

I plan to add more performance tuning tips in the future.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ashrafur Rahaman
Software Developer (Senior)
Canada Canada
Member
Software engineer with broad experience in enterprise application development, product deployment automation, software test & test automation, application & system management, and manage big projects and team using proven agile technologies.
 
Passionate on Microsoft technologies, developed solutions using C#, .net (1.1/2.0/3.5/4), SQL Server (2005/2008). Work on Powershell, SSRS, SSIS, WPF, Ajax, WCF, JQuery.
 
Develop innovative application with cutting edge technologies always boosting inside.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralThanksmemberkalpesh2118 Feb '13 - 1:20 
Thanks for ,Valuable information.

Visit for more info .

www.cyberzhub.com Wink | ;)
QuestionAnother good post for performancemembermitesh98757 Nov '11 - 18:42 
Just check http://howto-improveknowledge.blogspot.com/2011/11/performance-improvement-tips.html[^] -
which explain the how to find bottleneck for performance.
GeneralGreat and ExcellentmemberVinceMc14 Aug '09 - 3:39 
These Tips are really powerfull. Nice article!
GeneralHTTP CompressionmemberSameer Alibhai7 Aug '09 - 4:04 
Assalam alaikum Ashraf bhai Smile | :)
Nice article I read it then I realized it was written by you, great job!
 
Just 1 quick point, that HTTP Compression will reduce the amount of time it takes to transfer the page (which is more apparent for remote users), however, it should take even more CPU to process, so the page will actually load slower for local users (where network is very fast).
 
Author, SharpDeveloper.NET
 

GeneralDisable ViewStatemembermark4asp23 Jun '09 - 5:55 
It is more convenient to move ViewState to the session.
 
see: Keep ViewState out of Page for Performance Enhancement Redux
. It takes a few minutes to do this. The tiny amount of code you need is at the bottom of the link.
 
PS: ViewState is at least 5 times slower than Session state. Better to use session state rather than to slow your web pages down. What does session state cost you? If you need a couple of extra gigabytes of RAM for your server that can't do any harm can it? (nor can it cost you very much)
 
I found 2 really obnoxious items of ViewState. (a) DropDownLists with ViewState enabled and (b) repeaters, lists or grids with input buttons which link to a drill-down page. I disable ViewState on DropDownLists automatically and I replaced the input buttons in the list controls with an image inside a hyperlink [such that the hyperlink contains a querystring with the id of the item I want to drill down to].
GeneralImage/static file cachingmemberKen McAndrew2 Jun '09 - 2:14 
Another point that's more for IIS6 users is to implement caching on static files like images. There's a way in IIS6 to do this. I know IIS7 is automatically doing it (just as they run the ASP.NET engine for all files, so URL rewrites without a .aspx extension are possible), but I think most of us are still using Windows Server 2003.
GeneralRealy GreatmemberMohammad Jahedur Rahman1 Jun '09 - 18:37 
Thanks Ashraf vai for this great post. Smile | :)
 
Mohammad Jahedur Rahman
Senior Software Engineer
Brain Station-23

GeneralRe: Realy GreatmemberAshrafur Rahaman2 Jun '09 - 8:33 
you r welcome Smile | :)
 
Ashrafur Rahaman

GeneralPoint# 8memberCybernate29 May '09 - 8:06 
I think a better reasoning for point# 8 would be:
"Response.Redirect involves one round trip to client and back to server, where as Server.Transfer is handled at the server without involving client in the whole flow."
 
Regards,
Cybernate

QuestionRe: Point# 8memberKen McAndrew2 Jun '09 - 2:10 
One point on Response.Redirect vs Server.Transfer is bookmarking. If you use Server.Transfer, the URL of the page shows the previous URL, so if you bookmark the page, you aren't bookmarking the right page. For public sites, this is a major consideration to take into account. If someone has a different experience though, I'd like to hear it, because I'd like to use a more efficient model where possible.
GeneralMy vote of 5memberyordan_georgiev29 May '09 - 1:03 
Simple, concise and expert level listing. Thanks for sharing!
 
It is one thing to know what to want, second to really want it, third to know how to do it, fourth to be skillful to do it, fifth to actually do it and last but not least to not regret after doing it

GeneralRe: My vote of 5memberkalpesh2118 Feb '13 - 1:18 
Thanks for ,Valuable information.
 
Visit for more info .
 
www.cyberzhub.com Wink | ;)
GeneralPoint #9 needs more clarificationmemberT.D.Brown28 May '09 - 8:42 
This is a good list of items to change but the only issue I really have would be to reword #9 to say something like client side validation will speed things up but server side validation is still a must. If you just do javascript validation then you are opening up hacks to send data and bypass any validation rules you may have.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 28 May 2009
Article Copyright 2009 by Ashrafur Rahaman
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid