Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Google's JSAPI in production code?

Tags:

html

jquery

jsapi

Possible duplicate of:

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

also many other discussions, including:

Where do you include the jQuery library from? Google JSAPI? CDN? Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail


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"></script>
<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?
like image 588
Frank Krueger Avatar asked Jul 09 '09 22:07

Frank Krueger


4 Answers

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.

like image 103
Keith Bentrup Avatar answered Nov 02 '22 02:11

Keith Bentrup


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.

like image 30
Nosredna Avatar answered Nov 02 '22 02:11

Nosredna


The benefit is it's hosted on googles super low latency and fast servers. you can also just use

<script type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js”></script>

its the same effect.

like image 15
Fusspawn Avatar answered Nov 02 '22 02:11

Fusspawn


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().

like image 12
Amir Arad Avatar answered Nov 02 '22 01:11

Amir Arad