Skrubb
Skrubb

Reputation: 531

CDN fallback for jQuery-ui.min.js

I have a web app built using MVC 4, and wanted a safeguard in place against CDN fails. So in order to have this work, I set the app up to use CDN's at first go 'round, and if the CDN is down, it will fallback to local files. I am only referencing 4 jQuery files, and 3 out of the 4 are working fine and loading from the fallback local source. This one is not, however:

<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.0/jquery-ui.min.js" type="text/javascript"></script>
<script>
    if (typeof jQuery == 'undefined') {
        document.write(unescape("%3Cscript src='@Url.Content("~/Scripts/jquery-ui.min.js")' type='text/javascript'%3E%3C/script%3E"));
    }
</script>

I am sure I have the syntax correct, since it's the same way I built out the other ones, and those are working fine. Yes, I have the file "jquery-ui.min.js" in my Scripts folder, and I literally navigated to the url: https://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.0/jquery-ui.min.js and copied the contents into the js file in my scripts folder, so everything is the exact same. The app is just not loading the local file when I push it to fail. Anyone have any suggestions?

Upvotes: 2

Views: 1088

Answers (1)

Kevin B
Kevin B

Reputation: 95024

Instead of testing for jQuery to exist, test for jQuery UI to exist.

if (!jQuery.ui) {
    ...

Upvotes: 3

Related Questions