views:

3391

answers:

8

Possible duplicate of:

should-i-link-to-google-apis-cloud-for-js-libraries

also many other discussions, including:

http://stackoverflow.com/questions/547384/where-do-you-include-the-jquery-library-from-google-jsapi http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-goo


I was looking at the Tiny MCE plugin example and saw this code in the head of the document:

<script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
<script type="text/javascript">
    google.load("jquery", "1.3");
</script>

I've never seen this way to load jQuery.

  • Is this recommended for production?
  • What is the benefit of this method?
+9  A: 

Yes, definitely. Google encourages it. Everyone benefits. It's more likely to be in their cache, and it's one less file that you have to serve.

Keith Bentrup
Does it also take advantage of browser pipelining since it's on another server? (possibly the wrong term)
Ross
+7  A: 

The only benefit is its hosted on googles super low latency and fast servers. you can also just use

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js”&gt;&lt;/script&gt;

its the same effect.

Fusspawn
It's a nice benefit though. One less file to serve from your server, and the client may not have to download it at all because the more people that use this method, the greater the affect. It increases the chance that it will already be in their cache. Faster sites = happier visitors.
Keith Bentrup
Oh its an awesome benefit, I use it every chance i get, ( while keeping a copy locally for whem my inet die's and i still feel like coding. ) Im just keeping my fingers crossed the google CDN never drops, thatll brake a ton of websites.
Fusspawn
+2  A: 

I think this method will help you a lot for the following reasons:

Google uses a Content Delivery Network and that will make that the users that are far away from your location can download your jquery libraries faster than if they did that from your site.

Also it will reduces the request to your server and will make first time users to download jquery javascript from google's server, and if the user has been in another similar site with this kind of implementation he won't need to download it again.

So I think that this will help you app/site

chermosillo
+2  A: 

As others have pointed out answering similar questions, there's a downside. In some countries (such as Iran), these are apparently blocked, breaking the website.

Nosredna
Interesting point of view. Thanks.
cherouvim
+1  A: 

I believe that the Google JSAPI is also asynchronous and helps avoid the "toll booth" best described by "Imagine there's a 4-lane highway between your web browser and the internet itself. This highway is optimize to let pictures, text, and css fly by. But, when it comes to external scripts, the highway creates a toll booth that slows traffic. The worst part is that pictures text, and css caught behind these scripts have to wait until they pass through" - Andres Vidal

The toll-booth is critical and must be avoided at all times.

NTulip
+1  A: 

This method is fine to use in a internet apps not in Intranet. we can directly download

vijayan
A: 

keep in mind that google jsapi loads the scripts only after the document itself is loaded.

So, if (for example) you are using jquery's $(document).ready() in your web app, you'll have to switch to google.setOnLoadCallback().

Amir Arad
A: 

I'm trying to figure out how to use it and saw I need to have an API key, is that absolutely necessary? See here: http://code.google.com/intl/pl/apis/ajaxsearch/signup.html

I have a script that uses (script src="http://www.google.com/jsapi">(/script) (script) google.load("jquery", "1.2.6");

Do I need a key for that?

Kape
Posting it as a separate question would make more sense: much more people will see it.
Nikita Rybak