HI WELCOME TO SIRIS

Part 100 - What if CDN is down

Leave a Comment
we will disccuss
1. What if CDN is down?
2. How to fallback from CDN to use local copy of Jquery?

There are several benefits of referencing a resource from a CDN. We discussed these in Part 99 of asp.net mvc tutorial.



A CDN is an external resource and beyond our control. So, what if, CDN is down? How can we fall back from CDN to use local copy of Jquery.

The following code checks if jQuery is loaded and if it isn't, the jquery script will be loaded from our web server.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" 
        type="text/javascript">
</script>

<script type="text/javascript">
    window.jQuery || document.write('<script src="/MVCDemo/Scripts/jquery-1.7.1.min.js">\x3C/script>')
</script>

\x3C is hexadecimal for <

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.