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?
The benefit is it's hosted on googles super low latency and fast servers. you can also just use
its the same effect.
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 togoogle.setOnLoadCallback()
.this file is after compression is 24KB, Addition of such file will increase HTTP requests and waiting for the response and execution and parse time that browser will take... if you say the file itself is cached everywhere, even if the file is cached in the browser, don't forget to consider the time it takes to read from disk, execute and parse...
all of this for only getting the jQuery file or other common JS, I think referring directly to the requested resource is better
check Google's best practices for more info.
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
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.
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.