What is CDN Fallback ?


CDN stands for Content Delivery Network.

The benefit of loading libraries like jQuery and Bootstrap from a CDN is that If Server is located multiple geographical location. It read or load the files from the nearest server, which ultimately speed up the page response time. example:-






There are 2 popular CDN exists in the market  
1. Google  
2. Microsoft 

Google CDN:- https://developers.google.com/speed/libraries/


<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>

Microsoft CDN:- http://www.asp.net/ajax/cdn
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
Fallback means :- If CDN server fails then WHAT ?

In that scenario, It should read from your local server i.e.

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script>
<script>
if (typeof jQuery == 'undefined') {
    document.write(unescape("%3Cscript src='/js/jquery-2.0.0.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>

Or (Another Way) :: Both are same

<script src="//ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-2.0.0.min.js">\x3C/script>')</script>






No comments:

Post a Comment