Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to reference google's JQuery library?

Tags:

jquery

I have included a reference to Google's JQuery library in my markup:

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

Is it safe to do this? How do I know Google won't change the address, or remove it altogether? I really can't afford to have my app break without warning.

What do other people do?

like image 415
Urbycoz Avatar asked Jun 17 '11 07:06

Urbycoz


People also ask

Why do we use jQuery hosted library by Google?

Using the jQuery hosted library by Google permits to your page to be loaded faster. Indeed, the library is loaded at the same time of your page instead of after.

Should I serve all my JavaScript files from a hosted library?

There are many well known hosted libraries – the two most famous being Google and CDNJS. It might seem like a good idea to serve all your JavaScript files from these libraries, but that might not be a generally good idea. In this article, I’ll show you that the most important use-case for using them is jQuery.

What are the best JavaScript libraries to add to your website?

You can call on these well-known JavaScript libraries and add them to your site with a small bit of code. There are many well known hosted libraries – the two most famous being Google and CDNJS.

How to use jQuery with WordPress?

But if you want to use Google’s library for jQuery with WordPress, paste the following code into your theme’s functions.php file. wp_register_script (‘jquery’, “//ajax.googleapis.com/ajax/libs/jquery/$ver/jquery.min.js”, false, $ver);


1 Answers

Have the best of both worlds. Use theirs for fast, possibly pre-cached, delivery and in case their server goes down (more likely than them moving it) fallback to your own:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
    document.write(unescape("%3Cscript src='/path/to/your/jquery' type='text/javascript'%3E%3C/script%3E"));
}
</script>

Taken from: Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

like image 160
Mauvis Ledford Avatar answered Sep 19 '22 05:09

Mauvis Ledford