Including jQuery In Your Page

jQuery is such a popular JavaScript library that you're likely to run into in almost any site. We'll use it for our final.

When using jQuery, you usually attach the entire jQuery library to your webpage. After that, you can attach one or more other plugins to add enhanced functionality. The jQuery plugins are nothing more than additional JavaScript files.

Getting jQuery

While you can go to the jQuery site and download a copy of library and attach it to your page, it's not the best practice today.

Instead you should use a Content Delivery Network (CDN) to host the jQuery library. All you have to do is link to file on the CDN. The CDNs have beefier servers than you and can take advantage of caching. All of this will help speed up your website.

Google offers free hosting of the most popular JavaScript libraries and is very easy to use.

We can include a Google hosted version of jQuery by using the following HTML in our page:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

This link includes the jQuery library on our page. Keep in mind, that this link is version specific. The URL we used above included version 3.3.1 of jQuery, which is the current version as of November 2018 (of the version 3.x branch).

JavaScript Order

Any plugins or other code that relies on jQuery will have to be added after jQuery itself. In practice this means that jQuery is usually going to be the first JavaScript file you load.