Search code examples
jquerycdn

How do you use a cdn to host jQuery?


I have always used the jQuery file to use jquery. Recently I have heard about using a CDN. I wanted to ask how you use it, and what this line of code does:

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

Solution

  • 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>