Using Microsoft's CDN Service with jQuery

Microsoft yesterday announced it has created a new Microsoft Ajax CDN (Content Delivery Network) that provides caching support for Ajax libraries. The CDN contains copies of data, placed at various locations, to maximize bandwidth. For example if your website is hosted in Australia, but you’re a visitor from the United Kingdom, then the data must travel between those two points. A CDN allows the visitor in the UK to download the files near themselves as opposed to the server in Australia. This provides a real boost to a websites performance.

You can get a full listing of the JavaScript libraries (and associated URLs) we already have loaded in our CDN cache here. To use this with jQuery, simply add the full path to the CDN service:

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js"
type="text/javascript"></script>

Here’s a quick example of how to use this in Visual Studio.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Using Microsoft's CDN Service with jQuery</title>
<
script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js"
type="text/javascript"></script>
<
script type="text/javascript">
$(document).ready(function() {
$("div").one("click", function() {
var index = $("div").index(this);
$(this).css({ borderStyle: "inset", cursor: "auto" });
});
});
</script>
<
style type="text/css">
div
{
width: 60px;
height: 60px;
margin: 5px;
float: left;
background: green;
border: 10px outset;
cursor: pointer;
}
p
{
color: red;
margin: 0;
clear: left;
}
</style>
</
head>
<
body>
<
div></div>
<
div></div>
<
div></div>
<
div></div>
<
div></div>
<
p>Click a green square...</p>
</
body>
</
html>

If you copy the example above and run it locally, you’ll be using a copy of jQuery’s library that is closest to your current location.



Will you give this article a +1 ? Thanks in advance


About The Author

Malcolm Sheridan is a Microsoft awarded MVP in ASP.NET and regular presenter at conferences and user groups throughout Australia. Being an ASP.NET Insider, his focus is on web technologies and has been for the past 10 years. He loves working with ASP.NET MVC these days and also loves getting his hands dirty with JavaScript. He also blogs regularly at DotNetCurry.com. Follow him on twitter @malcolmsheridan

No comments: