# Friday, 24 January 2014

Accessing jQuery From Your Site

To start using jQuery, simply add a reference to the jQuery library as in the following example:

<script 
    type="text/javascript" 
    src="scripts/jquery-1.10.2.min.js"></script>

Of course, you will need to download jQuery from http://jQuery.com and save it in your site’s scripts folder for the location above to work. Also, the currently downloaded version may have a slightly different name as the version number is included in the file name.

Using a Content Delivery Network

Alternatively, you can connect to jQuery on a Content Delivery Network (CDN), such as one provided by jQuery, Microsoft, or Google, in the following manner:

<script 
  type="text/javascript" 
  src=“http://ajax.microsoft.com/ajax/jquery/jquery-1.10.2.min.js">
</script>

or

<script 
  type="text/javascript"
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>

or

<script 
  type="text/javascript" 
  src="http://code.jquery.com/jquery-1.10.2.min.js ">
</script>

A CDN offers the following advantages:

  1. A CDN has servers around the world, so it can serve up files closer to the client that requested them, so they download faster.
  2. Most web clients cache files by default, so the client may already have a cached copy of the jQuery script file and may not need to download it again.

Adding jQuery to your site or page is simple and fast. In my next article, I will talk about the syntax of jQuery and how to use it to select objects on a web page.