I have an Ajax.Net enabled ASP.Net 2.0 web site. Hosting for both the site and the database are out of my control as is the database's schema. In testing on hardware I do control the site performs well however on the client's hardware, there are noticeable delays when reloading or changing pages.

What I would like to do is make my application as compact and speedy as possible when I deliver it. One idea is to set expiration dates for all of the site's static resources so they aren't recalled on page loads. By resources I mean images, linked style sheets and JavaScript source files. Is there an easy way to do this?

What other ways are there to optimize a .Net web site?

UPDATE: I've run YSlow on the site and the areas where I am getting hit the hardest are in the number of JavaScript and Style Sheets being loaded (23 JS files and 5 style sheets). All but one (the main style sheet) has been inserted by and Asp. Why so many?


You could turn on compression based on your client supporting it. See this article: link text


Static resources shouldn't be resent unless changed. IIS will send a response code which tells the browser to use the cached version.

+18  A: 
  1. Script Combining in .net 3.5 SP1
  2. Best Practices for fast websites
  3. HTTP Compression (gzip)
  4. Compress JS / CSS (different than http compression, minify javascript)
    1. YUI Compressor
    2. .NET YUI Compressor

My best advice is to check out the YUI content. They have some great articles that talk about things like CSS sprites and have some nice javascript libraries to help reduce the number of requests the browser is making.

Darren Kopp
+3  A: 

Turn viewstate off by default, it will be a night and day difference on even the most simple pages.


I think you really need to be able to get some actual PerfMon data/telemetry from the app whilst running in production to be able to make an enlightened decision about what to optimise.

As a throw away tip I'd make sure your app is deployed as a Release build and set debug="false" in the 'compilation' section of your web.config.

+5  A: 

If you are using Firefox to test your website, you might want to try a nifty Firefox extension from Yahoo! called YSlow.

It analyzes your web pages and provides grades from A-F (A being the Best and F being the worst) for each of the best practices, for high performance websites. It will help you to track down the elements of your website which you could optimize to gain speedups.


You seem to be starting by assuming that your problem is download size - that may not necessarily be the case. You should do some experimentation with your ASP.NET site to determine if there are areas in your code which are causing undue delays. If it turns out that download size is not your problem, you'll need to find ways to cache your results (look into output caching, which is an ASP.NET feature) or optimize your code.

In any case - the first step when looking at a performance issue is always to verify your assumptions first, then decide on a course of action.

John Christensen
+2  A: 

I wrote a blog post about improving ASP.NET page performance this a couple months back. Here are some quick & easy ways -

  • Turn off view state
  • Turn off event validation
  • Implement HTTP gzip/deflate compression to reduce the response size (number of bytes the server has to send back to the client)
  • Try to optimize/minimize your database calls for each request

You could start looking at caching strategies. Static files like CSS (even compressed ones) and images (even optimized ones) should only need to be downloaded once by the browser for a period of time.

Scirpt combining for AJAX has already been mentioned, but I didn't notice reference to the ScriptReferenceProfiler MS has released on codeplex to help figure out what to combine. Mike Ormond has a good start point on this.

Another tip if you're doing a lot of INSERTs to your database is to double check your server's disk caching is switched on. Case in point, I had an data importer doing 1.2 million inserts during a run. Took 4 hours and change without caching on. Took 16 minutes with it on.


You could also look at ASP.NET output caching, which can be applied fairly granularly to different portions of your page:

+1  A: 

A general thing when using ASP.NET and Ajax (any Ajax library) together is to avoid elephanting your Page_Load and Page_Init (and their method counterparts) things since these will be executing on every Ajax Request.

When that is said I would seriously ditch ASP.NET AJAX and use anything else...

Anthem.NET, AjaxPRO.NET, jQuery or whatever else than ASP.NET AJAX...

Of course I would use Ra-Ajax myself since that's my project. But then again I am biased...

Thomas Hansen
plug plug plug....Zzzzzz