- Caching: The most important benefit is caching. If any previously visited site by user is using jQuery from Google CDN then the cached version will be used. It will not be downloaded again.
- Reduce Load: It reduces the load on your web server as it downloads from Google server's.
- Serves fast : You will be also benefitted from speed point of view. As Google has dozen's of different servers around the web and it will download the jQuery from whichever server is closer to the user. Google's CDN has a very low latency, it can serve a resource faster than your webserver can.
- Parellel Downloading: As the js file is on a separate domain, modern browsers will download the script in parallel with scripts on your domain.
How to use it?
There are 2 ways to load from Google CDN.
What if Google CDN is down?
It is a good idea to use CDN but what if the CDN is down (rare possibility though) but you never know in this world as anything can happen. So if you have loaded your jQuery from any CDN and it went down then your jQuery code will stop working and your client will start shouting.
Hang on, there is a solution for this as well. Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.
It first loads the jQuery from Google CDN and then check the jQuery object. If jQuery is not loaded successfully then it will references the jQuery.js file from hard drive location. In this example, the jQuery.js is loaded from Scripts folder.
If you want jQuery 1.7.1 you can use a url like this:
Suppose you want to use latest version of 1.7 release,
If you always want to refer the latest version of jQuery,
Feel free to contact me for any help related to jQuery, I will gladly help you.