Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are advantages of using google.load('jQuery', ...) vs direct inclusion of hosted script URL?

Google hosts some popular JavaScript libraries at: http://code.google.com/apis/ajaxlibs/

According to google:

The most powerful way to load the libraries is by using google.load() ...

What are the real advantages of using

google.load("jquery", "1.2.6")

vs.

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

?

like image 696
Vilmantas Baranauskas Avatar asked Oct 16 '08 14:10

Vilmantas Baranauskas


1 Answers

Aside from the benefit of Google being able to bundle multiple files together on the request, there is no perk to using google.load. In fact, if you know all libraries that you want to use (say just jQuery 1.2.6), you're possibly making the user's browser perform one unneeded HTTP connection. Since the whole point of using Google's hosting is to reduce bandwidth consumption and response time, the best decision - if you're just using 1 library - is to call that library directly.

Also, if your site will be using any SSL certificates, you want to plan for this by calling the script via Google's HTTPS connection. There's no downside to calling a https script from an http page, but calling an http script from an https page will causing more obscure debugging problems than you would want to think about.

like image 158
Eric Caron Avatar answered Sep 25 '22 02:09

Eric Caron