The forgotten performance optimization tricks for ASP.NET

Feb 12, 2006

There are a lot of articles explaining the basics in performance optimization in ASP.NET. Here is one and here is another. It is important to know the basics and use them where appropriate. The basics include caching, viewstate optimization etc. But what do you do to optimize further, when you have implemented all the basic techniques? You search the Internet to find an article about it, just like this one. The conclusion of this article is: Make the response from the server to the client as small as possible. You already have made the server-side code run fast with the basic techniques, so now you need to shrink the output. Here are a few examples that will take you a long way.

1. Remove whitespace in the HTML
This is very simple to do in ASP.NET. Here is the method to use.
It can easily reduce your html code by 15%.

2. Remove whitespace and comments in CSS and JavaScript files.
This is also very simple. Read this post on how that is done easily.
CSS code can be reduces by 30% and JavaScript about 15%-20%.

3. Put all styling in a stylesheet file
If you do a lot of styling in your html, the file size increases. Every time a page loads the styling is also returned from the server. But if you put all your style in a stylesheet, it will get cached by the browser and thereby only return from the server once. This can be a great improvement if you have a lot on in-code styling.

4. Put all JavaScript in .js files
This uses the same principle as my point about putting all style in stylesheets. Browsers caches .js files just like CSS files so it’s only returned from the server once. Again, the impact of this trick is dependant on the amount of JavaScript you use in your html page.

If you apply all four techniques, my guess is that you have reduced the response to a minimum. If you pay for the bandwith used by the website, this could save you a lot of money by reducing the filesize.

* $4.95/month BlogEngine.net Hosting – Click Here!

Comments (1) -

Dale Sides
Dale Sides United States
11/22/2008 1:21:10 AM #

I am glad to see someone blogging about this. The simple things that people used to do is being overlooked like white space, I remember bringing this topic up to a jsp and cold fusion developer way back in 2000 when he was complaining about performance issues on a server I was hosting for his company at the time. Granted white space was not the key performance issue he was facing (the big performance hit for them was full table scans in an oracle stored procedure), but just the fact that the enormous amount of white space in their pages told me that they were not paying attention to the small things.

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.