JQuery CDN Fallback

Cashing on CDN hosts like Microsoft, Google etc., for referencing jQuery & similar libraries is good performance optimization solution particularly for rich interactive web applications .

However, consider a worst case scenario where CDN network is down or somehow not accessible. You must plan a fallback for the scenario where CDN network, of course, would be first preferred source of rendering followed by your local copy. At the same time, you also wants to avoid duplication on libraries sent to end-user.

Here’s a fallback approach to address this scenario:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<script>window.jQuery || document.write('<script src="assets/js/libs/jquery-1.7.2.min.js"></script>')</script>
(Visited 16 times, 1 visits today)