codeofaninja
website

Including Google Hosted jQuery and other JS Libraries

Photo of Mike Dalisay
Modified Tuesday, April 5, 2011
by - @ninjazhai
When I'm testing my JavaScript with jQuery, sometimes, I feel lazy to locate on my hard disk where is that jQuery library file. At the same time, I don't want to download it on their website. So I thought of hosting it on a server and just specify its URL as a source of my <script> tag.

But then I found out that Google is hosting different JavaScript library for free. So now, I can access the library just by specifying the URL of Google-hosted jQuery library. Google hosts several open-source library which includes:


So now, here's how I include a jQuery library on my scripts.


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js "></script>



You may also use google.load function if you want. But you have to get your own API key. So I prefer accessing it in direct path (script above).


Here's a simple slide and toggel demo, with jQuery hosted by google.



Well actually, jQuery site also provide their script.

<script src="http://code.jquery.com/jquery-latest.js">
</script>

There are many debates whether to host your jQuery on Google or not. You may also read this article and its comments.
For FREE programming tutorials, click the red button below and subscribe! :)
Thanks for the comments!
 
 
Fundamentals
"First do it, then do it right, then do it better."
~ Addy Osmani
"Talk is cheap. Show me the code."
~ Linus Torvalds
Let's Stay Connected!
g+ r
Android app on Google Play
© 2011-2014 The Code Of A Ninja. All rights reserved. Proudly Powered by Google Blogger. Images, logos, marks or names mentioned herein are the property of their respective owners.