You can direct your browser to get a copy from the jQuery website, from your own server, from some other server where it is hosted –or you can load it from Google API server. The question is what is the best way to load jQuery? Well, obviously, it is the Google way. Here I will tell you why and what are the advantages of loading jQuery from Google API.
But first all, let’s see how to load it. Use the following line in the HEAD section of your webpage to load jQuery from Google:
You can change the version number depending upon which version you require for your website. I would recommend that you don’t use an automatic latest version of jQuery on your website. jQuery keeps on developing and changing. But the plugins and other codes on your website may require a specific version. So, it is better to use jQuery of a specific version number.
Now let’s talk about advantages of loading jQuery from Google’s server:
- Google API servers are distributed. They form a CDN (Content Delivery Network) and deliver content much faster. Browser will be able download the files from the server which is physically closest to the client machine
- Most servers force a limit on how many connections a browser can open. So, if jQuery is being loaded from Google –you save one connection to your own server and that can be used by the browser to download other stuff from your server. On busy websites and blogs, this could translate into a big resource saving.
- Because countless websites are already using jQuery from Google –there are high chances that the user will already have a copy of jQuery from Google in their local cache! This means that in some cases the browser will not even need to download jQuery files.
- If your host is charging you for data transfer (i.e. bandwidth) –then you’ll save money because jQuery’s download from Google is free.
Aren’t these significant benefits of loading jQuery from Google? I guess they are. If Google is hosting something for us for free, why not to use it?!
Please share what you think on this issue. Thank you for using TechWelkin.