Google Host jQuery

While searching for some jQuery tutorials, I come across to this website,
http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/

Doing so has several advantages over hosting jQuery on your server(s): decreased latency, increased parallelism, and better caching. It is quite interesting to know about the benefits of it.

Implementation method:
Google suggested method

<script type="text/javascript"
        src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  // You may specify partial version numbers, such as "1" or "1.3",
  //  with the same result. Doing so will automatically load the
  //  latest version matching that partial revision pattern
  //  (e.g. 1.3 would load 1.3.2 today and 1 would load 1.7.1).
  google.load("jquery", "1.7.1");

  google.setOnLoadCallback(function() {
    // Place init code here instead of $(document).ready()
  });
</script>

Normal method

<script type="text/javascript"
 src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    // This is more like it!
  });
</script>

If you’re curious why the script reference is missing the leading http:, that’s a helpful trick which allows you to use a single reference that works on both HTTP and HTTPS pages.

Besides Google, Microsoft also host the jQuery libraries. If want to call in this method,

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


Leave a comment