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?
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.
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.
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.
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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With