Home > Enterprise >  How do you use a cdn to host jQuery?
How do you use a cdn to host jQuery?

Time:11-09

I always use the code from the jQuery site in my code to use jQuery, and I have recently heard about using a cdn. How do I use one?

CodePudding user response:

A content delivery network CDN refers to a geographically distributed group of servers that work together to provide fast delivery of Internet content.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide();
  });
});
</script>
</head>
<body>

<h2>This is a heading</h2>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

<button>Click me</button>

</body>
</html>

CodePudding user response:

Do you mean any CDN or hosting yourself? Google has a CDN for jquery (found here https://developers.google.com/speed/libraries)

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

CodePudding user response:

This might be helpful to you

from https://code.jquery.com/

select jQuery version that you want (I prefer jQuery3.x minified).

When you select the jQuery version (also with options), you may copy script like

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj 3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

Insert script in html <head>:

...
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj 3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>
<body>
</body>
</html>
...

Hope this help you well

  • Related