Jquery Migrate CDN fallback condition
Asked Answered
H

1

5

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

Humpage answered 19/8, 2013 at 8:37 Comment(0)
S
9

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>
Smoothbore answered 19/8, 2013 at 8:41 Comment(2)
Any reference link to jQuery.migrateWarnings or $.fn.live ?Humpage
no... those are hacks because those properties will not be present in jQuery >= 1.9Smoothbore

© 2022 - 2024 — McMap. All rights reserved.