Using CDN for jQuery

by Craig 19. December 2011 19:02

Including a link to a CDN site is simple. Just add the link and go. There are potential complications, however, based on the client's needs.

Google, Microsoft and Yahoo all offer CDN links to provide the library for you. In general, the google API link is going to be more accessible, for various reasons. However, there are also libraries that are available on Microsoft that are not available on Google. There will be some cases where Google itself is not accessible, like in the case of government entities who block gmail for security reasons. There are also entities that block *.microsoft.com, usually for purposes of system controls to prevent users from getting downloads, etc.

That said, the easiest answer is to provide it yourself. But if that does not provide the performance you need, then the next best option is probably google for the core and UI, and whatever else you can get from another CDN, like validation from Microsoft. If not available, well, you'll just have to host it.

Now, keep in mind that if you have an SSL site, then pulling in items from other sites can be considered a violation of your secure site, and can compromise your site. In those situations, you're better off hosting the .js yourself, unless you consider it acceptable for the user to be prompted to load content from an insecure site.

One last consideration: if you have monthly bandwidth limitations like on this site, then pulling the libraries from elsewhere will reduce the traffic, and reduce your bill. Just FYI.

So, here are the links:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js" type="text/javascript"></script>

Or, if you prefer going the Microsoft route:

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

Just add those to your page (before any code that references them) and you should be good to go.

Tags: ,

Blog

Month List

About the author

I've been writing software for over 25 years, starting out on a PDP-11, jumping on the Internet in 1990, writing web applications since HTML 0.9 in 1993, and now in a loving relationship with Javascript and HTML using jQuery to make it all work brilliantly.

It seems that I'm always doing things for other people and/or companies, but I'm finally setting aside some time to set up my own site to publicly post some of the things I'm doing and/or exploring.  BlogEngine.NET seems to do that nicely, we'll see how well it holds out long term.

I'm not enabling comments just yet, since this web site doesn't really have a lot of space.  But I'll monitor the hits and if there's enough interest, I may upgrade and open it up.  Just depends.

Feel free to use the code and samples you find here (without any implied warranty or guarantee, of course...)  I usually create stuff under the GNU public license anyway, so just stick my name in there somewhere so that my reputation will be carried through with the work.  (Much appreciated...)

Hope you enjoy the site! Cool

Craig Warford
11/14/2010