asp:Feature
LANGUAGES:
C#
ASP.NET
VERSIONS: 2.0
It s All in the Timing
Reduce the Initial Load Time of Your ASP.NET Web Pages
By Joydip Kanjilal
This article highlights the strategies that one can adopt
for faster page renderings in ASP.NET. It discusses such factors as caching, viewstate,
and ASP.NET page precompilation.
The Strategies
To start, reduce your working set size by removing all
unnecessary .dll files. Reduce the size of your viewstate or disable it
altogether to minimize the size of your viewstate and thus facilitate faster
page rendering. You should disable viewstate for controls that do not require
it. Further, you can remove the runat= server form tag completely to reduce
page size by 20 bytes. If you don t remove this tag, the page itself passes on
about 20 bytes of information to viewstate, even when the page s ViewState
property is set to false.
Use ASP.NET 2.0 s new feature called precompilation
effectively to reduce the page load time of your Web pages by compiling the
application s code at run time. You can pre-compile Web pages in your
application to reduce the working set size and boost application performance.
ASP.NET 2.0 provides this excellent feature and makes it
available in the following two distinct modes:
- In-place precompilation
- Precompilation for deployment
You can learn more about precompilation, its types, and
benefits in my article Boost
ASP.NET Performance with Precompilation .
You can set the autoEventWireup attribute to false in
the Machine.config file to improve performance further. Refer to the code
snippet given here:
<configuration>
<system.web>
<pages
autoEventWireup="true|false" />
</system.web>
</configuration>
The autoEventWireup attribute accepts a Boolean value that
indicates whether the ASP.NET page s events are auto-wired. If the autoEventWireup
is set to false, the runtime does not have to look for each of the page event
handlers. MSDN states, When you explicitly set AutoEventWireup to true, Visual
Studio .NET or Visual Studio 2005, by default, generates code to bind events to
their event-handler methods. At the same time, the ASP.NET page framework
automatically calls the event-handler methods based on their predefined names.
This can lead to the same event-handler method being called two times when the
page runs.
Further, ensure that the tables, cells, and images you use
in your Web pages have their width and height set properly so that the browser
can prepare placeholders for items and render faster. Avoidance of excessively
large images, nested tables, and redundant tags in the Web pages would also
yield a faster page render.
You can use caching for better performance of successive
page renderings. It is great for storing relatively static application data as
it reads data from memory to avoid repeatedly retrieving data from a database,
file, or any other repository. Judicious use of the right type of caching can
go a long way toward improving the performance of your ASP.NET applications,
and it can reduce the time required for successive page renderings where your Web
page requires relatively static data.
You can check the load time of your ASP.NET Web pages by
enabling the trace in the page. For this, enable the trace option in your .aspx
file and set the TraceMode property = SortByTime . Refer to the code snippet
below:
<%@ Page Language="C#"
AutoEventWireup="true" trace="true"
TraceMode="SortByTime" CodeFile="Test.aspx.cs"
Inherits="Test" %>
Follow these additional strategies for improving the
overall performance of your ASP.NET Web applications:
- Avoidance of unnecessary roundtrips to the Web
server through the use of client-side scripts
- Efficient exception handling and data access
strategies
- Optimized code for efficient garbage collection
Read my article Improving Application Performance in .Net to learn more
about the strategies that can be followed to improve the overall performance of
your ASP.NET Web applications.
Conclusion
In essence, one should be aware of the most important
strategies on how to optimize the applications so that they have the least
amount of memory, processor, network, and IO overload. Here we took a quick look
at some of the best measures for improving the response time of your ASP.NET Web
pages.
Working extensively in Microsoft technologies for more than 10
years, Joydip Kanjilal is a Senior
Technical Leader in the Design and Architecture team for a company in Hyderabad,
India. His programming
skills include C, C++, Java, C#, VB, VC++, ASP.NET, XML, and UML. An ASP.NET
MVP, he has worked with .NET and C# for more than five years. Reach Joydip at mailto:joydipkanjilal@yahoo.com or
at his blog at: http://aspadvice.com/blogs/joydip/.