Loading the JQuery JS Code into your Site

Two Choices -- Upload or CDN

From your HTML experiences you know how to upload files. You can use the same technique to upload JQuery to your web site as you would use to upload a single HTML file. That's one option, and it's a good option for many of us.

Your second option is this: Load JQuery from a CDN and just enter the JavaScript code you're using in the page. No worries about uploading.

Let me take a second to explain a CDN... it's a content delivery network. They generally speed up the loading of resources on web sites. For example, imagine a web site with some fancy graphics. Normally, all these graphics would load from one server (either the HTTP server from the hosting package or a special image server). This is great, but someone on another continent in the world may experience a loading delay. Wouldn't it be great if the resources for a web site would load around the world to a server close to each person?

Let's get back to my example. Right now, my web server is in the southern United States. Someone accessing my web site from Canada would be pulling the data all the way across North America. Someone from Europe or Asia would be taking even more time. Yeah, with fiber optics, stuff travels fast, very fast. But having local content is an even better idea. So I use a content delivery network, and I put my images on there. When someone from Asia loads my web site, the images come from a server close to them. When someone from Europe loads my web site, the images come from a server close to them. The CDN just to have copies of my resources, and my web site has to say "grab these images from the CDN."

You don't have to pick and get contracts with each individual server company. You don't hire someone from the United States, someone from England, someone from Japan. You hire one company to take care of all those details and do all the hard work.

Here's the benefit now. You can either upload a copy of JQuery to your web space (which is optimal for a lot of people with fast servers) or you can link to a public file on a CDN provided by Google.

Here's the breakdown of your two choices:

 load your JQuery here from your server (local
                JavaScript) after uploading it
 type your JQuery for your page here
 load the JQuery here from a CDN (content delivery network)
 type your JQuery for your page here

I'm only going to detail the second approach. Uploading a copy of JQuery to your own web site is covered in detail on the JQuery web site. Here's the current code to load JQuery from Google:

<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

So, adding that HTML line above the code in part 1 and part 2 is what allows your JQuery code to work right. Pretty simple copy and paste to add a lot of features to your web site, right?

JQuery - Next Section Coming Soon. Back to Chapter List