jquerycdngoogle-cdnjquery-migrate

Jquery Migrate CDN fallback condition


To increase page speed am using Google CDN to download jquery file and I also have fall back to download jquery from local incase Google CDN fails.

Below is how am using fallback

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

</script>

Above code works perfect, my question is how to check if jquery migrate file is loaded or not?

All I need is to check if http://code.jquery.com/jquery-migrate-1.1.0.js is loaded or not. I hope if (typeof jQuery == 'undefined') {} this wont work here.

Any solutions


Solution

  • You can check for the existance of $.fn.live method or jQuery.migrateWarnings object

    <script type="text/javascript" src="http://code.jquery.com/jquery-migrate-1.1.0.min.js"></script>
    <script type="text/javascript">
    if (typeof jQuery.migrateWarnings == 'undefined') { // or typeof jQuery.fn.live == 'undefined'
        document.write(unescape("%3Cscript src='common/script/jquery-migrate-1.1.0.min.js' type='text/javascript'%3E%3C/script%3E"));
    }
    
    </script>