jQuery Installation


Adding jQuery to a Web Page

You can add jQuery to a web page in multiple ways. You can use the following methods:

  • fromjquery.comDownload the jQuery library
  • Load jQuery from a CDN, such as from Google.

Download jQuery

There are two versions of jQuery available for download:

  • Production version - Used for actual websites, minified and compressed.
  • Development version - Used for testing and development (uncompressed, readable code)

Both of the above versions can be downloaded fromjquery.comdownload from.

The jQuery library is a JavaScript file that you can reference using the HTML <script> tag:

<head> <script src="jquery-1.10.2.min.js"></script> </head>

Tip:Place the downloaded file in the same directory as your web page, and you can use jQuery.

lamp Are you wondering why we didn't use type="text/javascript" in the <script> tag?

In HTML5, you don't need to do that. JavaScript is the default scripting language in HTML5 and all modern browsers!


Alternatives

If you don't want to download and host jQuery, you can also reference it via a CDN (Content Delivery Network).

Staticfile CDN, Baidu, Upyun, Sina, Google, and Microsoft servers all host jQuery.

If your site's users are in China, it is recommended to use domestic CDN addresses such as Baidu, Upyun, and Sina. If your site's users are overseas, you can use Google and Microsoft.

Note:All examples on this site use the Example CDN library.

If you need to reference jQuery from Staticfile CDN, Upyun, Sina, Google, or Microsoft, use one of the following code snippets:


Baidu CDN:

<head> <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"> </script> </head>

Try it »

CDNJS:

<head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> </head>

Try it »

Upyun CDN:

<head> <script src="https://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.2.min.js"> </script> </head>

Try it »

Staticfile CDN:

<head> <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"> </script> </head>

Try it »

Google CDN:

<head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script> </head>

Try it »

lamp It is not recommended to use Google CDN to get the version, because Google products are very unstable in China.

Microsoft CDN:

<head> <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script> </head>

Try it »

lamp Using jQuery from Staticfile CDN, Baidu, Upyun, Sina, Google, or Microsoft has a big advantage:

Many users have already loaded jQuery from Baidu, Upyun, Sina, Google, or Microsoft when visiting other sites. As a result, when they visit your site, they will load jQuery from cache, which reduces loading time. Also, most CDNs can ensure that when users request a file, the response is returned from the server closest to the user, which also improves loading speed.

jQuery Version Used

We can use in the browser's Console window$.fn.jquerythe command to view the current version of jQuery used:

Other Extensions