how to fallback twitter-bootstrap cdn to local copy [duplicate] how to fallback twitter-bootstrap cdn to local copy [duplicate] javascript javascript

how to fallback twitter-bootstrap cdn to local copy [duplicate]


This is what I did and it works fine

<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script><script>    $.fn.modal || document.write('<script src="Script/bootstrap.min.js">\x3C/script>')</script>


I didn't see a specific variable that twitter-bootstrap exposes for this purpose and they don't attach all of their plugins to a namespace a la jQuery UI. Your next best bet is to test for one of the bootstrap plugins. Perhaps something like this:

if(typeof($.fn.modal) === 'undefined') {    //load bootstrap locally}

The unfortunate thing about this is that it is brittle. If the modal plugin is ever renamed or removed this check would always fail.