English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this chapter, you will learn how to integrate jQuery into your web page.
There are two ways to use jQuery:
FromjQuery.comDownload jQuery library
Include jQuery from the CDN, such as Google, Baidu, etc.
Firstly, please download a copy of jQuery and include it in your document.
There are two versions of jQuery available for download:
Compressed version-For your live website as it has been minimized and compressed
Uncompressed version-For testing and development (uncompressed and readable code)
You can download from the followingWebsite URLDownload both versions:https : //jquery.com/download/.
After downloading the jQuery file, you will see that it has a .js extension, because jQuery is just a JavaScript library, so you can include the jQuery file in your HTML file<script>element, just like adding a regular JavaScript file.
<head> <script src="jquery-3.4.1.min.js"></script> </head>
Always include the jQuery file before the custom script; otherwise, when your jQuery code tries to access the jQuery API, they will not be available.
If you do not want to download and host jQuery yourself, you can include it from a CDN (Content Delivery Network).
Both Staticfile and Microsoft provide the latest version of content delivery.
Please use either of the following methods to use Staticfile or Microsoft's jQuery:
<head> <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script> </head>
<head> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.min.js"></script> </head>
By hosting jQuery on servers worldwide, CDNs can provide performance advantages. This also offers an advantage that if your web visitors have already downloaded a jQuery copy from the same CDN, there is no need to download it again.
Advantages of using jQuery CDN:
When visiting another site, many users have already downloaded jQuery from Staticfile or Microsoft. Therefore, when they visit your website, the file will be loaded from the cache, thus shortening the loading time. Moreover, most CDNs ensure that once a user requests a file, it will be provided from the server closest to them, which will also shorten the loading time.