Three quick ways optimize AJAX driven websites in ASP.NET

April 18th, 2008

Recently I was involved in a project where I had to make heavy use of AJAX. I realized there are a few simple things you could do to improve performance.

1) Combine scripts

<ajaxToolkit:ToolkitScriptManager ID=”TSM1” runat=”Server”
EnablePartialRendering=”true”
CombineScriptsHandlerUrl=”~/CombineScriptsHandler.ashx” />

As the name of the property suggests, it will pretty much combine all the needed JS files into one which in turn will reduce the number of requests sent to the server. You can find a detailed discussion about this here.

It is pretty easy to implement; instead of using the regular ScriptManager, just switch to the ToolkitScriptManager which comes with the AjaxToolkit and then set its CombineScriptsHandlerUrl property as shown above and throw the CombineScriptsHandler.ashx (included in the “SampleWebSite” directory of AjaxControlToolkit’s release package) into the root.

2) Run in release mode

The debug versions of the AJAX library have their source formatting preserved, as well as some debug asserts. By running it in release mode you can shave off some bytes off your requests.

<ajaxToolkit:ToolkitScriptManager ID=”TSM1″ runat=”Server” 
EnablePartialRendering=”true” ScriptMode=”Release” />

Although, its important to note that some versions of Safari don’t seem to be compatible with this and could cause many strange side effects as this person and I have experienced in the past.

On a side note, ASP.NET AJAX Control Toolkit officially does not support Macs with PowerPC processors, its good to know that piece of information if a client ever demands an explanation as for why AJAX powered functionality seems to be broken or not functioning as expected in that environment.

3) Enable script caching and compression in web.config


<system.web.extensions>
  <scripting>
    <scriptResourceHandler enableCompression=true
     enableCaching=true/>
  </scripting>
</system.web.extensions>

This will compress and cache all the script files which are embedded as resources in an assembly, localization objects, and scripts that are served by the script resource handler.

But like the previous tip, there is a exception to this one too. Some versions of IE6 have a bug where they cant’t handle GZIP’d script files correctly. The RTM version of ASP.NET AJAX works around this by explicitly not compressing files for these versions of IE. Although if you are still having a problem, it just might be a safe bet to explicitly set the enableCompression property to false in the web.config.

Programming | Comments | Trackback Jump to the top of this page

2 comments on “Three quick ways optimize AJAX driven websites in ASP.NET”

  1. 01

    Hey! Yes def. going to be a techie blog :-)

    Bina at April 21st, 2008 around 9:28 pm
    Jump to the top of this page
  2. 02

    Good list!

    I might add “combining ASP.NET AJAX script method proxies”, and, one wide open question on optimization using the AJAXControlToolkit might be how to automatically remove comments / minify the javascript in the toolkit. Even with the ToolkitScriptsManager in Release mode, comments and whitespace are preserved in script delivered to the browser.

    Daniel at April 22nd, 2008 around 12:07 pm
    Jump to the top of this page

Leave a Reply

  •  
  •  
  •  

You can keep track of new comments to this post with the comments feed.


Recently on Flickr

  • IMG_0514
  • IMG_0506
  • IMG_0505
  • IMG_0503
  • IMG_0497
  • IMG_0495
  • IMG_0494
  • IMG_0493

Switch Theme

Meta