Adding jQuery to your projects

There are two ways to add jQuery to your projects

  • Download the jQuery library file and store it within your project

  • Use a CDN (content delivery network) and reference the jQuery library file remotely


Option #1 - Download jQuery file(s)

This approach assumes you downloaded the jQuery file and stored it on your js folder

<html>
  <head>
    <title>Add jQuery by downloading jQuery file(s)</title>
  </head>
  <body>

    <script src="js/jquery-3.4.0.js"></script>
    <script src="js/app.js"></script>
  </body>
</html>


Option #2 - Use a CDN (Content delivery network)

This approach references the jQuery file that lives on a CDN (another server)

<html>
  <head>
    <title>Add jQuery using a CDN</title>
  </head>
  <body>

    <script src="https://code.jquery.com/jquery-3.4.0.js"></script>
    <script src="js/app.js"></script>
  </body>
</html>


Content Delivery Networks (CDNs)

  • A content delivery network (CDN) places files in different locations so that the person using your webpage can receive the nearest copy of it faster

  • Prevents your users’ browsers from downloading commonly used libraries(like jQuery) every time they visit your site

  • Use of CDNs increases page speed for highly trafficked sites

  • Click here for a nice overview of CDNs