Click here to Skip to main content
15,512,565 members
Articles / Web Development / ASP.NET
Posted 11 Jan 2015


31 bookmarked

Ten Simple Tips to Improve Performance of an ASP.NET Website

Rate me:
Please Sign up or sign in to vote.
4.71/5 (23 votes)
11 Jan 2015CPOL4 min read
Tips to improve the performance of ASP.NET web applications


In this tip, we will look at various aspects of improving the performance of ASP.NET web applications.

Performance is an important aspect of the modern day web application development. Here are some tips that you can consider while making a better performing website.

1. Upgrade Your ASP.NET Framework

Check your .NET framework. If you can upgrade your site to use .NET 4.5, then it has some great performance optimizations. .NET 4.5 has a new Garbage Collector which can handle large heap sizes (i.e., tens of gigabytes). Some other improvements are Multi-core JIT compilation improvements, and ASP.NET App Suspension. These optimizations do not require code changes.

2. Caching

  1. Use output caching – Use output caching for regularly used views or pages which have no dynamic updates. The easiest way to implement cache on MVC view is to add an [OutputCache] attribute to either an individual controller action or an entire controller class. Here is a controller action Index() that will be cached for 15 seconds.
    [OutputCache(Duration = 15, VaryByParam = "None")]
    public ActionResult Index(string Id)
  2. Use Data caching - Reduces the database or the disk I/O by caching the regularly used data to in-memory cache. This avoids repeated queries for data, and it can improve performance and scalability. In addition, caching makes data available when the data source is temporarily unavailable. The .NET Framework provides classes that enable you to use caching facilities in ASP.NET applications. These classes are defined in the System.Runtime.Caching namespace.

3. Always keep CSS and JavaScript External

Never add any JavaScript or inline style information within the views. That would regenerate the view each time and you would miss out on the benefits of the Caching. Hence always keep JS and CSS as separate files and add them as links in the view.

4. File Compression

There are often requests to the web server with lot of static content. These contents can be compressed thereby reducing the bandwidth on requests. The following setting is only available in II7 and later.

        <urlCompression doStaticCompression="true" doDynamicCompression="true" />  

The urlCompression name sounds strange but it is not really the compressing of URLs. It means compressing or gzipping the content that is sent to the browser. By setting to true/enabling, you can gzip content sent to the browser while saving lots of bandwidth.

5. Bundling and Minification

The custom CSS files and the JavaScript files should be bundled into a single large file (reduces the number of HTTP requests) and also minified (reduces the size of the data transferred over the wire).

6. CDN (Content Delivery Network)

All the 3rd party JavaScript files such as JQuery, Knockout should always use the CDN instead of the web application server. CDN Servers are dedicated to deliver the static content and is always faster than your own host. There is a very high probability that the client (browser) would have already cached the JavaScript as part of other web application since most of them use the same CDN URL.

7. Control Image Requests

There are couple of ways to do this.

  1. Image sprite - With image sprite, you can combine multiple different images into a single large image. Then use CSS to reposition those images within the site.
  2. Base64 Data URIs - With this option, you would never make any requests to the server to obtain any images.

8. Script Rendering Order

Move the script tags <script> to the very bottom of the page. The reason this is important is because during the rendering, when the browser comes across a <script> tag, it stops to process the script and then moves ahead. If you put the script tags at the bottom of the page, the page/HTML will render faster and the scripts can execute after the DOM elements have loaded. Sometimes moving the script to the bottom of the page is not possible as some DOM elements or CSS may depend on these scripts, so they can be rendered. In such cases, you could move those scripts further up the page.

There are some other ways:

  1. defer attribute
    <script src="some.js" defer>

    Using the defer attribute, you can specify the script not to run until the page has been fully loaded.

  2. async attribute
    <script src="some.js" async>

    Using the async tag, the scripts will be run asynchronously, as soon as it is available.

9. Removing Default HTTP Modules in ASP.NET

ASP.NET has many http modules waiting for request to be processed and would go through the entire pipeline even if it’s not configured for your application.

All the default modules will be added in the machine.config place in“$WINDOWS$\Microsoft.NET\Framework\$VERSION$\CONFIG directory. One could improve the performance by removing those modules which you wouldn’t require.

10. Compile in Release Mode

Always set the build configuration to release mode for the website.

In this tip, we looked at some of the approaches that you can take to make optimized and better performing web sites. This included, reducing number of requests to the server, changes to the .NET framework, and compressing techniques.


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

Written By
Software Developer Global Infonet Inc
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralMy vote of 2 Pin
Santosh K. Tripathi12-Jan-15 18:33
professionalSantosh K. Tripathi12-Jan-15 18:33 
SuggestionDetails Pin
Ciprian Beldi12-Jan-15 0:17
Ciprian Beldi12-Jan-15 0:17 
GeneralRe: Details Pin
Member 1033810512-Jan-15 9:40
Member 1033810512-Jan-15 9:40 
QuestionAlways add external JS/CSS Pin
Muhammad Hassan Tariq11-Jan-15 22:05
professionalMuhammad Hassan Tariq11-Jan-15 22:05 
GeneralRe: Always add external JS/CSS Pin
Member 1033810512-Jan-15 9:32
Member 1033810512-Jan-15 9:32 
GeneralMy vote of 4 Pin
Reelix11-Jan-15 21:01
Reelix11-Jan-15 21:01 
Whilst a fantastic article for the most part, I must disagree with 7.a.

If you had one large image, none of the images on the site would load until the entire map has loaded, which would lead to a rather jarring user experience. With multiple smaller images, each can be loaded independently, and it has frequently been proven that this results in an overall faster speed (See multi-section download managers for example)
GeneralRe: My vote of 4 Pin
Member 1033810512-Jan-15 10:04
Member 1033810512-Jan-15 10:04 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun11-Jan-15 19:56
Humayun Kabir Mamun11-Jan-15 19:56 
GeneralMy vote of 3 Pin
DotNetCodebased11-Jan-15 14:43
DotNetCodebased11-Jan-15 14:43 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.