A new JavaScript CDN from Microsoft

Microsoft announced a new Content Delivery Network for their ASP.NET AJAX JavaScript libraries and jQuery. This means that instead of hosting those libraries on your server, you can just link to the versions on Microsofts server. I made a simple page that takes a querystring parameter (q=) and uses the ASP.NET AJAX dynamic templates to bind search results from a call to the Bing API.

The money lines in the source are the following:


<script type="text/javascript"
src="http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjax.debug.js"></script>

<script type="text/javascript"
src="http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxTemplates.js"></script>

These two lines tell the browser to load the MS AJAX scripts from the CDN. There are some security concerns around the fact that the files are served from the microsoft.com domain. Both Google and Yahoo serve there files from a separate, non-cookied domain (googleapis.com and yahooapis.com respectively). Hopefully, these fears will be unfounded.

On a side note, it is surprisingly easy to use the Bing API if you are familiar with script tag injection. The easiest way is to put an empty script tag in your page.

<script id="jsonResults" type="text/javascript"></script> 

And then just create your Bing URL and set the script elements src attribute to the URL you created.

			function MakeSearchRequest(searchPhrase)
			{
				var req = "http://api.bing.net/json.aspx?"
	            + "AppId=" + YOUR API KEY GOES HERE
	            + "&Query=" + searchPhrase
	            + "&Sources=Web"
	            + "&JsonType=callback"
	            + "&JsonCallback=BuildResults";
				
				$get("jsonResults").src = req;
			};