[jquery] Installing jQuery?

What is the procedure for installing jQuery for someone new to it?

This question is related to jquery

The answer is


There are two ways to load jQuery in your application:

1) Add jQuery from your own site.

For this, you need to add jQuery reference in <Head> section of your page with correct src path:

<script src="script/jquery.js" type="text/javascript"></script>

But this create an additional load to your server for download a file to client

2) ther other way to load jQuery from any other server like Google, Microsoft or jQuery itself.

As stated here:

it provides several advantages.

  1. You always use the latest jQuery framework.
  2. It reduces the load from your server.
  3. It saves bandwidth. jQuery framework will load faster from these CDN.
  4. The most important benefit is it will be cached, if the user has visited any site which is using jQuery framework from any of these CDN.

Here is the link by which you can load jQuery from Microsoft. Follow this url, it may be helpful.

http://www.asp.net/ajaxlibrary/cdn.ashx


The following steps can be followed

1) Download Jquery by clicking on this link DOWNLOAD

2) Copy the js file into your root web directory eg. www.test.com/jquery-1.3.2.min.js

3) In your index.php or index.html between the head tags include the following code, and then JQuery will be installed.

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

The best thing would be to link to the jQuery core is via google.
There are 3 reasons to do it this way,

  • Decreased Latency
  • Increased parallelism
  • Better caching

      see:
      http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
 $(document).ready(function() {

Your code here.....

  });
</script>

Well, as most of the answers pointed out, you can include the jQuery file locally as well as use Google's CDN/Microsoft CDN servers. On choosing Google vs. Microsoft CDN go Google_CDN vs. Microsoft_CDN depending on your requirement.

Generally for intranet applications include jQuery file locally and never use the CDN method since for intranet, the LAN is 10x times faster than Internet. For Internet and public facing applications use a hybrid approach as suggested by cowgod elsewhere. Also don't forget to use the nice tool JS_Compressor to compress the extra JavaScript code you add to your jQuery library. It makes JavaScript really fast.


There is no installation per se.

You download jQuery and include it in your html files like this:

<script src="jquery.js" type="text/javascript"></script>

Of course, modify the filename so that it's the same as the downloaded script file.

Done!


jQuery is just a JavaScript library (simply put, a JavaScript file). All you have to do is put it into your website directory and reference it in your HTML to use it.

For example, in the head tag of your webpage

<script type="text/javascript" src="../Js/jquery.js"></script>

You can download the current jQuery release from Downloading jQuery.


It tells you at the very start of the tutorial linked from the jQuery homepage.


There is none. Use script tags to link to google's version (or download it yourself and link to your copy if you really want to).

If you don't know how to do that, learn HTML and Javascript first before attempting to learn jQuery.


There is no installation required. Just add jQuery to your application folder and give a reference to the js file.

<script type="text/javascript" src="jQuery.js"></script>

if jQuery is in the same folder of your referenced file.


There are two different ways you can utilize jQuery on your website. To start off, you need to have access to your website source, whether it be straight HTML or generated HTML from a programming language. Then you need to insert a <script> tag that will render in the final output to the web browser.

Because you are new to jQuery, I highly suggest you start reading How jQuery works.

As others have mentioned, there are Content Distribution Networks (CDNs) that host JQuery -- all you need to do is point your script tag src to a specific URI. Google and Microsoft both have CDNs that are free for personal and commercial use.

Alternatively, you can download jQuery and host it on your own website.

You can also leverage both of these methods together. In the event that the Google or Microsoft CDN is down or blocked in the end user's country/firewall/proxy, you can fallback to your locally hosted copy of jQuery.


As pointed out, you don't need to. Use the Google AJAX Libraries API, and you get CDN hosting of jQuery for free, as depending on your site assets, jQuery can be one of the larger downloads for users.


Install JQuery with only JavaScript. This is not a very good solution if you are developing a website but it's great if you want JQuery in the JavaScript console of a random website that does not use JQuery already.

function loadScript(url, callback)
{
    // adding the script tag to the head as suggested before
   var head = document.getElementsByTagName('head')[0];
   var script = document.createElement('script');
   script.type = 'text/javascript';
   script.src = url;

   // then bind the event to the callback function 
   // there are several events for cross browser compatibility
   script.onreadystatechange = callback;
   script.onload = callback;

   // fire the loading
   head.appendChild(script);
}
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js")

loadScript function thanks to e-satis's answer to Include JavaScript file inside JavaScript file?


If you want to use a package manager,

You can use bower:

bower install jquery-ui