Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

jQuery installation


May 07, 2021 jQuery


Table of contents


jQuery installation


Add jQuery to the page

There are several ways to add jQuery to a Web page. You can use the following methods:


Download jQuery

There are two versions of jQuery available for download:

  • Production version - Used in actual sites, has been streamlined and compressed.
  • Development version - for testing and development (uncompressed, readable code)

Both versions are available for download jquery.com .

The jQuery library is a JavaScript file that you can refer to using html's hashtag:

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

Tip: You can use jQuery by putting the downloaded files in the same directory of your web page.

jQuery installation Are you wondering why we didn't use type"text/javascript" in the hashtag?

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


Alternatives

If you don't want to download and store jQuery, you can also reference it through the CDN (Content Distribution Network).

The servers of Baidu, Sky, Sina, Google and Microsoft all have jQuery.

If your site users are domestic, it is recommended to use Baidu, and shoot cloud, Sina and other domestic CDN addresses, if your site users are foreign users can use Google and Microsoft.

Note: This site examples are using Baidu jQuery CDN library.

To quote jQuery from Baidu, Sky, Sina, Google or Microsoft, use one of the following codes:

Baidu CDN:

<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js" rel="external nofollow" >
</script>
</head>

Try it out . . .

Another shot cloud CDN:

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

Try it out . . .

Sina CDN:

<head>
<script src="http://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js" rel="external nofollow" >
</script>
</head>

Try it out . . .

Google CDN:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" rel="external nofollow" >
</script>
</head>

Try it out . . .

jQuery installation Get the latest available versions with Google CDN:

Google CDNs are not recommended for versions because Google products are unstable in China.
If you're looking at what's on the Google URL - the jQuery version (1.8.0) is specified in the URL. If you want to use the latest version of jQuery, you can also remove a number from the end of the version string (e.g. example 1.8), Google will return the latest available version in the 1.8 series (1.8.0, 1.8.1, etc.), or it can only have the first number left, then Google will return the latest available version in the 1 series (from 1.1.0 to 1.9.9).

Microsoft CDN:

<head>
<script src="http://ajax.htmlnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js" rel="external nofollow" >
</script>
</head>

Try it out . . .

jQuery installation Using Baidu, Cloud, Sina, Google or Microsoft's jQuery has one big advantage:

Many users have already loaded jQuery from Baidu, Sky, Sina, Google or Microsoft when they visit other sites. A ll results are that when they visit your site, jQuery is loaded from the cache, which reduces load time. At the same time, most CDNs can also improve loading speed by ensuring that when a user requests a file from them, a response is returned from the server closest to the user.