06 February 2011 CDN, Fallback, jQuery CI Team

imagejQuery is one of the populates javascript frameworks. But it´s not the smallest one. To save traffic and reduce the waiting time while loading you should try out the "CDN" (hosted) jQuery version. But how is it possible to run a local backup plan in emergency case? Go on reading if you are interested in the answer...

JQuery CDN

jQuery it self´s, Google and Microsoft are offering jQuery (+ some well-known Plugins) for linking on their servers. More about this you can read here.

Why should I do this?

There are several reasons for using the hosted version:

- You save the traffic. jQuery and co. are able to take a lot of space on the traffic.

- Google and co. CDNs are created to do this job. If someone is able to offer such content very fast than networks like this.

- For a long time browsers are not able to load more than two Javascript files from one domain. If you use jQuery from google.com your Browser will be able to load other application specific files at the same time. If this is important today is the question Zwinkerndes Smiley

- Many people use Google or Microsoft services or visit websites which are linked by their jQuery Version. That means, you have the big chance, that your browser already cached jQuery somewhere - shorter waiting times while loading!

- More information´s you will find on the Yahoo best practices site.

Which CDN is the best for me? Microsoft or Google?

At least both services are almost equal if we talk about the jQuery hosting. But probably there are more people using Google CDN - that means you have bigger chances if you use Google. On the other hand Microsoft included some gadgetry for ASP.NET developer with the Script Manager - but actually we don´t need it Smiley mit herausgestreckter Zunge

Here is a little discussion on Stackoverflow: Microsoft CDN for JQuery or Google CDN?

Why shouldn´t we use it?

Of course there are also some disadvantages. You can´t use it for intern applications (but you don´t need it there) and also you need to trust the provider - anyway there is a kind of dependency.

What happens if there are any kinds of problems on Google/Microsoft/jQuery CDN?

Hm... In my opinion you shouldn´t be scared that one of the CDNs will go down but maybe there could be a problem reaching the CDN. Because of this I recommend you to create your own Backup and link it in emergency cases:

<script src="//code.jquery.com/jquery-1.4.4.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="LOKALER_JQUERY_PFAD"%3E%3C/script%3E'))</script>

Instead of "LOKALER_JQUERY_PFAD" you easily enter your own pad. In line one CDN jQuery is linked by jQuery. Little hint: If we talk about a HTTP side http://code.jquery.... Will be used. But HTTPS sides are called https:// ... . That´s because of this "//" Syntax.

If code.jQuery.com is down anyway

With Java Script the local version will be linked in this case automatically.