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
- Use page caching:
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.
<add name="cached" duration="600"
- Remove unnecessary
httpModules from the web.config:
<remove name="WindowsAuthentication" />
<remove name="PassportAuthentication" />
<remove name="AnonymousIdentification" />
<remove name="UrlAuthorization" />
<remove name="FileAuthorization" />
- Turn off trace:
<trace enabled="false" pageOutput="false" />
- As I have used membership, I disabled automatic save for profiles:
<profile enabled="true" automaticSaveEnabled="false" />
4. Implement Cache Dependency
Three types of cache dependencies are available:
- Caching Dependency on cached items
- Cache Dependency on a file
- 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%.
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.
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:
- 26th May, 2009: First version.
I plan to add more performance tuning tips in the future.
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.