To load jQuery from the official CDN, go to the jQuery website. You'll see a list of different versions and formats available.
Now, copy the source of the version of jQuery, you want to load. Suppose, you want to load jQuery 2.X, click uncompressed or minified tag which will show you something like this:
Copy the full code (or click on the copy icon) and paste it in the <head>
or <body>
of your html.
The best practice is to load any external JavaScript libraries at the head tag with the async
attribute. Here is a demonstration:
<!DOCTYPE html>
<html>
<head>
<title>Loading jquery-2.2.4</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" async></script>
</head>
<body>
<p>This page is loaded with jquery.</p>
</body>
</html>
When using async
attribute be conscious as the javascript libraries are then asynchronously loaded and executed as soon as available. If two libraries are included where second library is dependent on the first library is this case if second library is loaded and executed before first library then it may throw an error and application may break.