Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Why a lot of locations? Because the web works by sending and receiving packets of information across different physical locations. The closer a user is to your server, the faster the data will get to them. A CDN puts multiple copies of the files across different physical locations. The users will always get the one that is closest to them. Yahoo!'s developer network, Google and others encourage the use of CDNs. Yahoo! has an excellent document on speeding up your web site at this URL.
I like to use this particular link right here, which is the minified version of jQuery, and this happens to be the latest version as of this video. You can find older versions by clicking on this link. There is a couple of problems with using Google's CDN that you should be aware of. The first one is that if there is a connection problem with the CDN, the script will not load. Chances are that Google's CDNs are more reliable than most servers. The more likely problem is that you might be developing code on your local machine without a connection to the Internet.
So I'm going to go back into codesnippets and show you the version that you should be using which has essentially two script tags for each one of our libraries. The first script tag adds our Google CDN to jQuery right here. And then on the next line, it checks to see if that CDN has already loaded by checking to see if the window.jquery function exists. If it doesn't exist, then it's going to write out to our current document a link to our current local version of the library. So if we copy these things, go back to our index page, and replace our calls to our library, you'll see that it still works fine.
Get unlimited access to all courses for just $25/month.Become a member