Click here to Skip to main content
15,878,959 members
Articles / Web Development / ASP.NET

A Way to Improve Performance of your Web Application Significantly

Rate me:
Please Sign up or sign in to vote.
5.00/5 (8 votes)
1 May 2011CPOL3 min read 26.6K   13   8
A way to improve performance of your web application significantly

For the last few days, I was working on performance improvement of one of my Web applications. I analyzed my application in various ways. I also used different profilers and did profiling for my application using several profilers like Ants, .NET profiler, etc. During analysis, I found a few problems that we rectified but got no visible improvement.

Later I thought, my server side code is good enough, but still it's taking time to download the page. Although we are already using IIS compression to reduce the page size, still Page was taking a good amount of time to download.

I posted a blog to enable IIS compression.

Actually, my application is a RIA application and we are using myriad ajaxtoolkit controls in our application. I analyzed my application using firebug and there are a lot of scriptresource.axd and webresource.axd files getting downloaded.

So I thought if we can combine these files into a single one, that will be a great performance application boost for our application.

First, I tried doing it by myself. Later, I found ASP.NET itself provides a way to combine these axd files. You just need to have .NET 3.5 SP1.

So if you are using framework version 3.5, upgrade it to SP1 and enjoy this feature.

I have created a small sample and will show you with the help of it.

So in my sample application, I have a Calender extender. Let's see how many requests are there using firebug.

Requests of a Web Page

We can see currently that there are 14 requests on every PageLoad. We can reduce the number of requests.

So to use this, first you need to download a ScriptReferenceProfiler. You can download it from here.

Now add the reference in your project and add the profile in your page.

First register it as:

ASP.NET
<%@ Register Assembly="ScriptReferenceProfiler" Namespace="ScriptReferenceProfiler"
    TagPrefix="cc2" %>

and add it as a control like:

ASP.NET
<cc2:ScriptReferenceProfiler ID="ScriptReferenceProfiler1" runat="server" >
</cc2:ScriptReferenceProfiler>

Now when you run your application, you will see the page.

Now copy all the links and put it in the CompositeScript tag as:

ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
            <CompositeScript>
                <Scripts>
                    <asp:ScriptReference name="MicrosoftAjax.js"/>
	                <asp:ScriptReference name="MicrosoftAjaxWebForms.js"/>
	                <asp:ScriptReference name="AjaxControlToolkit.Common.Common.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
	                <asp:ScriptReference 
			name="AjaxControlToolkit.Common.DateTime.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
	                <asp:ScriptReference 
			name="AjaxControlToolkit.Compat.Timer.Timer.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
	                <asp:ScriptReference 
			name="AjaxControlToolkit.Animation.Animations.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
	                <asp:ScriptReference 
			name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
	                <asp:ScriptReference 
			name="AjaxControlToolkit.Animation.AnimationBehavior.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
	                <asp:ScriptReference 
			name="AjaxControlToolkit.PopupExtender.PopupBehavior.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
	                <asp:ScriptReference 
			name="AjaxControlToolkit.Common.Threading.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
	                <asp:ScriptReference 
			name="AjaxControlToolkit.Calendar.CalendarBehavior.js" 
			assembly="AjaxControlToolkit, Version=3.0.30930.28736, 
			Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
                </Scripts>
            </CompositeScript>
        </asp:ScriptManager>

Now let's run the Application. Let's check the firebug.

Combined requests

Here we can see the number has significantly reduced. It’s just 4.

But this is a sample and it's working fine. But when you try in your actual application, you might face several issues.
I faced one issue while using with my Live applications.

Issue: The resource URL cannot be longer than 1024 characters. If using a CompositeScriptReference, reduce the number of ScriptReferences it contains, or combine them into a single static file and set the Path property to the location of it.

So first, I could not understand it and tried to find something on Google. But somewhere, I found it’s a issue and it will be taken care of or handled by itself for the time being. But during analysis, I found one solution.

The problem is the URL length is getting higher than 1024. So for this, one has to reduce the number of files getting combined. So you can have more than one group of files and put it in different composite scripts tag.

I have added one script manager proxy and added a compositscript tag it in it and pasted almost half of the scripts in it. And it resolved the issue as:

ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
           <CompositeScript>
               <Scripts>
                   <asp:ScriptReference name="MicrosoftAjax.js"/>
                   <asp:ScriptReference name="MicrosoftAjaxWebForms.js"/>
                   <asp:ScriptReference name="AjaxControlToolkit.Common.Common.js"
           assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
                   <asp:ScriptReference
           name="AjaxControlToolkit.Common.DateTime.js"
           assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
                   <asp:ScriptReference
           name="AjaxControlToolkit.Compat.Timer.Timer.js"
           assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
               </Scripts>
           </CompositeScript>
       </asp:ScriptManager>
       <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
           <CompositeScript>
               <Scripts>
               <asp:ScriptReference name="AjaxControlToolkit.Animation.Animations.js"
       assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
                   <asp:ScriptReference
           name="AjaxControlToolkit.ExtenderBase.BaseScripts.js"
           assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
                   <asp:ScriptReference
           name="AjaxControlToolkit.Animation.AnimationBehavior.js"
           assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
                   <asp:ScriptReference
           name="AjaxControlToolkit.PopupExtender.PopupBehavior.js"
           assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
                   <asp:ScriptReference
           name="AjaxControlToolkit.Common.Threading.js"
           assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
                   <asp:ScriptReference
           name="AjaxControlToolkit.Calendar.CalendarBehavior.js"
           assembly="AjaxControlToolkit, Version=3.0.30930.28736,
           Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
               </Scripts>
           </CompositeScript>
       </asp:ScriptManagerProxy>

Now it will combine the resource files in two files. You can add more CompositeScript tags if required.

Hope all of you have enjoyed this and benefited from it.

Cheers,
Brij

Image 3 Image 4 Image 5 Image 6 Image 7 Image 8 Image 9 Image 10

License

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


Written By
Software Developer (Senior)
India India
Brij is a 3-times Microsoft MVP in ASP.NET/IIS Category and a passionate .NET developer. More than 6 years of experience in IT field, currently serving a MNC as a Tech Lead/Architect.

He is a very passionate .NET developer and have expertise over Web technologies like ASP.NET 2.0/3.5/4.0, jQuery, JSON, Javascript, IIS and related technologies. He is also a Exchange Server (EWS) Specialist. He has great experience in design patterns and N-Tier Architecture.

He is also certified as Microsoft Certified Technologies Specialist-ASP.NET and Microsoft Certified Technologies Specialist-WCF in .NET 4.0. He has also received several awards at various forums and his various articles got listed as "Article of the day" at ASP.NET Microsoft Official Website www.asp.net.

He has done MCA from NIT Durgapur and completed his graduation from Lucknow University.

Learning new technologies and sharing knowledge excites him most. Blogging, solving problems at various forums, helping people, keeps him busy entire day.


Visit his Blog: Code Wala

Area of Expertise :
C#, ASP.NET 2.0,3.5,4.0, AJAX, JQuery, JSON, XML, XSLT, ADO.Net, WCF, Active Directory, Exchange Server 2007 (EWS), Java script, Web Services ,Win services, DotnetNuke, WSS 3.0,Sharepoint Designer, SQL Server 2000/2005/2008

Comments and Discussions

 
GeneralMy vote of 5 Pin
zhxhdean9-Dec-12 18:38
zhxhdean9-Dec-12 18:38 
GeneralMy vote of 5 Pin
Akram El Assas12-May-12 4:57
Akram El Assas12-May-12 4:57 
GeneralGreat! Pin
simijohn12-Jun-11 21:43
simijohn12-Jun-11 21:43 
GeneralRe: Great! Pin
Brij12-Jun-11 22:01
mentorBrij12-Jun-11 22:01 
GeneralMy vote of 5 Pin
Kunal Chowdhury «IN»3-May-11 0:38
professionalKunal Chowdhury «IN»3-May-11 0:38 
GeneralRe: My vote of 5 Pin
Brij3-May-11 4:27
mentorBrij3-May-11 4:27 
Thanks Kunal!!
Cheers!!
Brij
Visit my Blog: http://brijbhushan.net


GeneralMy vote of 5 Pin
koolprasad20031-May-11 18:14
professionalkoolprasad20031-May-11 18:14 
GeneralRe: My vote of 5 Pin
Brij1-May-11 20:21
mentorBrij1-May-11 20:21 

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.