Viewers: in countries Watching now:
- Creating variables, functions, and loops
- Writing conditional code
- Sending messages to the console
- Working with different variable types and objects
- Creating and changing DOM objects
- Event handling
- Working with timers
- Building smarter forms
- Using regular expressions
We've seen that it's simple to download jQuery so that you have a copy of the file on your site to send to your users. But there is a better way: let somebody else do it. Several companies, including Google and Microsoft, allow you to link to jQuery, and some other common libraries, and get that file directly from their servers. And they don't just have one server but typically a bunch of geographically distributed servers with load balancing and failover, all in a Content Distribution Network, or CDN, so it's almost always faster for the user to get it from one of their servers than from your server.
So if that user then goes to another site and retrieves some HTML and CSS that's also using that same CDN and that same path, the browser will realize, hey, I've already got a copy of that jQuery file. I don't need to download it at all. So I've talked about jQuery here, as it's the most common, but if you want to know what other libraries are available, we'll get in more details, go to code.google.com/apis/libraries.
Now one more thing: you'll see that Google makes this path available as https here. That's where it showing up in this list. In fact, it is available as both http and https paths. The main reason it needs to be available as an https address is so you can use it from an encrypted page without the browser complaining that you're using an unencrypted asset on that page. There really is no other benefit to encrypting jQuery; everybody knows what it is.
But if your site needs to link to jQuery from pages at a variety of http and https addresses, one shortcut is that in your link to that file you actually just remove the protocol from the link, so you remove http: or https: and just have the two forward slashes. It looks a little strange, but that will just use whatever protocol the current page is using. And that's all there is to it. The only place I wouldn't use Google's CDN is if I was developing a purely internal intranet site where my users are literally in the same building as the web server.
But otherwise, I highly recommend a CDN as your default way of linking to a library like jQuery. There really are no downsides here.