Improving AJAX Performance

When you start sending large amounts of script code to the client, you have to keep performance in mind. There are many tools you can use to optimize the client-side performance of your site, including YSlow for Firebug (see http://developer.yahoo.com/yslow/), and the developer tools for Internet Explorer (see http://msdn.microsoft.com/en-us/library/dd565629(VS.85).aspx). In this section we'll provide a few performance tips.

Using Content Delivery Networks

Although you can certainly work with jQuery by serving the jQuery scripts from your own server, you might instead consider sending a script tag to the client that references jQuery from a content delivery network (CDN). A CDN has edge-cached servers located around the world, so there is a good chance your client will experience a faster download. Because other sites will also reference jQuery from CDNs, the client might already have the file cached locally. Plus, it's always great when someone else will save you the bandwidth cost of downloading scripts.

Microsoft is one such CDN provider you can use. The Microsoft CDN hosts all the files used in this chapter. If you want to serve jQuery from the Microsoft CDN instead of your server, you can use the following script tag:

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"
        type="text/javascript"></script>

You can find the list of URLs for and see all the latest releases on Microsoft's CDN at http://www.asp.net/ajaxlibrary/CDN.ashx ...

Get Professional ASP.NET MVC 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.