jQuery

jQuery Google | jQuery Google Latest – Include latest jQuery from Google/jQuery CDN

If you always wondered what jQuery Google latest is but didn’t know what it really means, then this article is for you. In this article, I am going to tell you  what jQuery Google latest is, why I recommended using it & how it can be used to ease up your web development process and how to make your website pages load faster. You can follow the instructions and implement the once and for all (permanently) without having to keep switching to a latest version of jQuery, whenever one is released. In short, you can use the code provided in this article, include it in your website once & it will always include the latest minified version of jQuery from Google automatically. Excited? Read on to find out more.

jQuery Google Latest | Google jQuery Hosting – Always Include latest jQuery from Google/jQuery CDN

If you already know about the intro about jQuery hosted on Google and would like to skip to the code directly, then simply click here. Or if you would like to read an intro about it and the advantages of always including the latest jQuery from Google, then continue to read on.

jQuery, as you know is an awesome JavaScript framework (If you would like to know more about jQuery, then read my article on What jQuery is, why to use jQuery and how to use jQuery). When developing websites, you may have noticed that jQuery releases periodical updates that can be really helpful as they fix bugs (if any), add new features, deprecate any older functions, etc. So you might come around a tutorial on the internet that shows you how to do things the new way by including the latest jQuery in their demo/scripts. And if you do implement those tutorials in your website and try to run it then you ultimately risk breaking that specific (new) functionality on your website. You may be wondering that you are using the exact same code but still you cant figure out what’s wrong and why the script is not working. After hours (or even days) of struggling with it, you may eventually realize that you forgot to include the latest version of jQuery! So is there any way to fix this automatically without having you to manually update is to the Google latest jQuery version? Fortunately, there is!

Enter “Hosting latest version of jQuery from Google/jQuery CDN“! Instead of including the jQuery script from your local files, you can now can just make including latest jQuery from jQuery CDN, always & automatically it or from Google hosted servers (with minor changes to script tag)! I am going to give a quick definition of CDN (as I am going to be using that word quite few times through this article) & then I will talk about some of the advantages of including Google jQuery hosting, followed by the actual code.

Quick Definition of CDN:

A CDN stands for Content Delivery Network. This network focus on distributing your static content across servers in various, diverse physical locations. That said, when a browser resolves the URL for these files that are included in the webpage (such as javascript), the script will be downloaded/made available from  the closest available server in the network.

Advantages of always including latest version of jQuery from Google/jQuery CDN

  • No manual update required – Once you implement the code provided in this article, you no longer will have to update to the newest version of jQuery, whenever one becomes available. The newer version of jQuery is automatically included for you. So this decreases maintenance & increases your productivity. This is true if you choose to include jQuery from jQuery CDN. But if you include it from Google CDN, you will have to update the script name again.
  • Access to the latest additions – You can always take advantage of the latest features without having to worry about including the latest jQuery version. Simply go ahead & make your changes & that’s it! Again, this is true in case of including jQuery from jQuery CDN. In case of Google CDN, you will have to make sure that you have updated the script URL to take advantage of the newest version.
  • Parallel Download/Parallelism – Usually the web browsers limit the number of connections that can be made simultaneously, to avoid overloading servers unnecessarily. So depending on the browser that is being used at that point of time, you may be limited to as low as two connections per hostname. So if you opt to use jQuery/Google AJAX Libraries, CDN eliminates one request to your site, allowing more of your local content to downloaded in parallel. It may not seem like a huge difference if the browser allows multiple concurrent connections, but for users who are running a browser that allows minimum concurrent connection, the difference can be noticed.
  • Decreased latency –When the latest version of jQuery is included from jQuery/Google’s AJAX Libraries CDN, the browsers of users who are located physically away from your server, will be able to download jQuery faster from jQuery/Google’s servers. So this will reduce the time their browser spends on fetching the copy of jQuery. So if your website is focused on targeting only a specific region of the globe and you are absolutely certain that your audience reach may never go beyond your targeted region & if your webserver is located in the same place as your consumers, then you may opt to include a copy of jQuery on your servers.
    If this is not the case and you have visitors all over the globe, then including jQuery from jQuery/Google’s AJAX Libraries CDN will fasten up browsing experience for users who are away from your web server’s physical location. And the best part is that using jQuery/Google’s CDN is free! So it be a worthy move to include jQuery from jQuery/Google’s library.
  • Caching – The biggest advantage of including jQuery from Google CDN or jQuery CDN is that your website users may not need to download jQuery at all. The browsers will be able to download it once from the CDN and they will be able to use this cached copy. And this speeds up browsing speed tremendously.

 How to always include latest jQuery version from Google for any website.

Well ok, so here’s the part that you were waiting for.

Code to always include latest jQuery from jQuery CDN in a regular website:

<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>

Code to always include latest jQuery from Google CDN in a regular website:

//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js

In the above code, make sure that you don’t include http: in front of //ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js. It is intentionally made that way as it allows you to use a single reference that works on both HTTP and HTTPS pages. You may use http: in front of it, if you are not using a web server altogether i.e. when you might be working on HTML pages & including jQuery in it. So if you are working on a website that needs a web server, such as PHP, WordPress, Joomla, etc. you can safely omit using http:

Code to always include latest jQuery from Microsoft CDN in a regular website:

http://ajax.microsoft.com/ajax/jquery/jquery-1.8.2.min.js

Code to always include latest jQuery from jQuery CDN in a WordPress theme/website:

<?php
function my_jquery_enqueue()
{
	//If any jQuery is already included, deregister it
	wp_deregister_script('jquery');

	//Register our jQuery from jQuery hosted servers
	wp_register_script('jquery', 'http://code.jquery.com/jquery-latest.min.js', false, null);

	//Enqueue the latest version of jQuery registered in the above step, to be used in the website
	wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'my_jquery_enqueue');
?>

Code to always include latest jQuery from Google CDN in a WordPress theme/website:

[php]

<?php

function my_jquery_enqueue()
{
//If any jQuery is already included, deregister it
wp_deregister_script(‘jquery’);

//Register our jQuery from Google hosted servers
wp_register_script(‘jquery’, ‘//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js’, false, null);

//Enqueue the latest version of jQuery registered in the above step, to be used in the website
wp_enqueue_script(‘jquery’);
}
add_action(‘wp_enqueue_scripts’, ‘my_jquery_enqueue’);
?>

[/php]

Code to always include latest jQuery from Microsoft CDN in a WordPress theme/website:

<?php
function my_jquery_enqueue()
{
	//If any jQuery is already included, deregister it
	wp_deregister_script('jquery');

	//Register our jQuery from Microsoft hosted servers
	wp_register_script('jquery', 'http://ajax.microsoft.com/ajax/jquery/jquery-1.8.2.min.js', false, null);

	//Enqueue the latest version of jQuery registered in the above step, to be used in the website
	wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'my_jquery_enqueue');
?>

jQuery CDN vs Google CDN vs Microsoft CDN for jQuery:

You might be wondering which option to go with, for choosing to host your jQuery file with. Here’s what I recommend:

jQuery CDN – There’s no maintenance required for it, whatsoever. It’s automatically updated, thereby providing you all new features without having to mess with the script tag tweak.

Google CDN – If you have no issues in changing the script tag manually each time jQuery is updated & you would like to use Google to host it as they have broader coverage than jQuery CDN.

Microsoft CDN – If you are a Microsoft fan!

There are some other differences but they are not important if you just need to include latest version of jQuery.

That’s it for this article!

Do you know of any other ways to use latest version of jQuery from Google/jQuery/Microsoft CDN? Feel free to suggest by commenting below.

Share your thoughts, comment below now!

*

*