New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Understanding and installing jQuery

From: JavaScript and AJAX

Video: Understanding and installing jQuery

jQuery is a framework that fixes compatibility issues that happen with JavaScript in older browsers. The library also gives you a lot of additional tools for working with the DOM. One of my favorite features of the framework is how easy it makes it to work with AJAX. So let's go ahead and take a look at some of the options you have for installing jQuery. So there's two ways you can include jQuery into your projects. You can download a copy or use it from a CDN. A CDN is a content delivery network. You can see links to those if you click on the Download tab right here and then look over here to the left.

Understanding and installing jQuery

jQuery is a framework that fixes compatibility issues that happen with JavaScript in older browsers. The library also gives you a lot of additional tools for working with the DOM. One of my favorite features of the framework is how easy it makes it to work with AJAX. So let's go ahead and take a look at some of the options you have for installing jQuery. So there's two ways you can include jQuery into your projects. You can download a copy or use it from a CDN. A CDN is a content delivery network. You can see links to those if you click on the Download tab right here and then look over here to the left.

Those are links to the most popular CDN libraries that have jQuery. You can also try cdnjs.com; that has copies of a lot of libraries, including jQuery. So the advantage of using a CDN is that if a browser has loaded your library from a CDN when you visited some other website, it may already be cached in your browser when it comes to your site, so your page will load a lot faster. The disadvantage is that CDNs will only work while you have a live connection to the Internet. If you're working with a local copy or maybe flying around on an airplane or coding where your connection is spotty, then the CDN is not going to load at all and none of your JavaScript will work.

So you load them both into your code in pretty much the same way. So let's go ahead and go to the front of the jQuery website and click on this Download link. Now, before you do that, see that there's two options here. You have the option of downloading a Production version or a Development version. Now, the Development version has a copy of all the code with comments that's super easy to read, but it's obviously a lot bigger. Whereas the Production is minified and Gzipped, which means that it's compressed, it has no comments, a lot of the variable names have been changed so that they're smaller, and it's really pretty impossible to read.

You should use the Development version if you're going to be editing something about the jQuery JavaScript code; otherwise, just use the Production version, and that's what I'm going to do. So I'll click on Download jQuery. Sometimes you see this kind of code right here, which is essentially the JavaScript code for jQuery. I told you the Production version was hard to read, and I wasn't kidding. Now, to save this I'm going to go to the File menu-- I'm using Safari right now--and I'm going to select Save As. And here I'm just going to rename this jquery.js and I'll just save it on the Desktop.

I want to make sure that from this Format menu, I choose Page Source. Make sure it's not in Web Archive. So I'll select that, hit Save, and now that saves it into our desktop, so I'm going to switch there. And what I need to do now is copy this into my server, so I'll copy that just by dragging it. I'm using Transmit as my FTP program, so there it is. It's already on my server. And now what I want to do is select the files that I need and open them up in my editor. So I've got all these files opened up in my editor.

There's the jquery.js library. I really don't need to see it, so I'm just going to close it up. What I need to do to insert it is go to my index.html file and then load it up just like I would any other script. I want to make sure that I load it up before my script.js, because that's where I'm going to be putting my regular JavaScript and I want to make sure that the library is there before my other scripts load. So I'll do a script tag, and as the source I'll just type in jquery.js. I don't need this part. Now, the only difference between this and loading it from a CDN is that if you were to load this from a content delivery network, you'd want to get the URL of the library and just copy that from here and paste it into your script tag.

But I'm not going to do that because I'm just using a local copy. So save it and now jQuery will load into my application, and it's ready for me to use. Loading up jQuery is normally done using one of the CDNs when you're in production, but keep in mind that if you're going to be offline and developing, then downloading a copy is a super-smart idea. One more thing: you should always load jQuery before your regular JS file. That way all the power of the framework is going to be available when you write your scripts.

Show transcript

This video is part of

Image for JavaScript and AJAX
JavaScript and AJAX

21 video lessons · 18479 viewers

Ray Villalobos
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.