WordPress – CDN Hosted jQuery

WordPress is a great platform it is so flexible and easy to use. Some issues that WordPress has is self hosted scripts. Who wants the overhead of all these scripts that your server has to handle. Not me and you shouldn’t also. To give you a little insight on self hosted scripts. One they make your website slower. Two it is just one more file on your already growing server. Three why not use something that is secure, faster, and simple.

Why To Use Self Hosted?

OK really there is not a ton of reasons why you shouldn’t use a CDN version of jQuery. I can really only think of 2 reasons. One if for some reason the CDN (Content Delivery Network) site was to go down you would lose your script. Two when you update WordPress they make sure you are up to date with the newest version.

Why Not To Use Self Hosted?

There are a ton of reasons why you should use CDN but I am only going to fill you in on the best. One using scripts from a CDN like google or jQuery.com will take load off your servers internal requests. Two some WordPress themes are not up to date with the newest jQuery so if you update WordPress you can break your site. Three I have only ever seen Google go down once and it was for like 10 seconds. Four and probably the most important, including scripts through a CDN looks great to search engines.

How To Implement

You do not need to be a rocket scientist to implement this. All that you have to do is, go to your functions.php file and copy the code below and paste it in there. Now the code below has 2 options for CDN’s and you only need 1 so delete the one you don’t want. Personally I would recommend Google. Mainly because googleapis.com is on a secure connection. Once you copy and paste you are all set. The comments in the code will explain what is happening in the code.