CDN to host jQuery

jQuery setup
Officially there are two ways of using jQuery:
- CDN Based Version - You can include jQuery library into your HTML code directly from Content Delivery Network (CDN).
- Local Installation - You can download jQuery library on your local machine and include it in your HTML code.
CDN Based Version

A CDN (Content Delivery Network or Content Distribution Network) is a network of proxy servers globally distributed throughout multiple geographic locations where end users can access cached content. Several tech giants ( Google , Microsoft etc.) offer copies of jQuery libraries hosted on their CDN. Using a CDN can offers better performance of your jQuery (and website as a whole). In order to load a hosted jQuery library, copy and paste the HTML code for that library (shown below) in your HTML page.
Google CDN
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
Microsoft CDN
<head>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>
</head>
FullSource using Google CDN
<html>
<head>
<title>jQuery Google CDN Setup</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</script>
</head>
<body>
<h1>jQuery Google CDN Setup</h1>
</body>
</html>
We recommend that you load jQuery libraries from the CDN via HTTPS, even if your own web-pages only uses HTTP.
CDN for jQuery has many advantages. The major advantage is the loading speed because CDN is made for faster loading. So jQuery library gets downloaded very fast from CDN (Content Delivery Network) , in this case making your web-pages to load faster by a few milliseconds .Local Installation
There are two versions of jQuery libraries accessible for downloading from websites:
- Production version - this is for your live website because it has been minified and compressed.
- Development version - this is for testing and development (uncompressed and readable code).
<head>
<script src="jquery-3.5.1.min.js"></script>
</head>
However, it's normally a better idea to hold the file name the same as when you downloaded it from CDN websites, as it contains the jQuery version . Also, most web-sites have a different directories for their JS files so you'll need to use the full-path in this case.
FullSource
<html>
<head>
<title>jQuery Setup</title>
<script type = "text/javascript" src = "/jquery/jquery-3.5.1.min.js">
</script>
</head>
<body>
<h1>jQuery Setup</h1>
</body>
</html>
Related Topics