I have a couple of JavaScript files that I use on every single project and currently use CDNJS to load them.
However, I was trying to see if there was a good way to check if the CDN is available, or if the files are available from the CDN. Then of course, if the files are not available on the CDN, I would load them locally.
Here are the JS files I currently use:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>window.jQuery || document.write('<script type="text/javascript" src="./scripts/jquery.min.js">\x3C/script>')</script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/retina.js/1.0.1/retina.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.3.0/respond.js"></script>
<!--[if (gte IE 6)&(lte IE 8)]>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/selectivizr/1.0.2/selectivizr-min.js"></script>
<![endif]-->
As you can see, if I have a fallback for loading jQuery, but not for any of the other files.
Any help would be greatly appreciated!
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/retina.js/1.0.1/retina.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.3.0/respond.js"></script>
<script>
window.jQuery || document.write('<script type="text/javascript" src="./scripts/jquery.min.js">\x3C/script>')
window.Modernizr || document.write('<script type="text/javascript" src="./scripts/modernizr.min.js">\x3C/script>')
window.RetinaImage || document.write('<script type="text/javascript" src="./scripts/retina.js">\x3C/script>')
window.respond || document.write('<script type="text/javascript" src="./scripts/respond.js">\x3C/script>')
</script>