Jquery迁移CDN后备条件

Gan*_*h K 5 jquery cdn google-cdn jquery-migrate

为了提高页面速度我使用谷歌CDN下载jquery文件,我也回退到从本地下载jquery谷歌CDN失败.

以下是使用后备的方法

<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>
Run Code Online (Sandbox Code Playgroud)

上面的代码是完美的,我的问题是如何检查是否加载了jquery迁移文件?

我只需要检查是否加载了http://code.jquery.com/jquery-migrate-1.1.0.js.我希望if(typeof jQuery =='undefined'){}这不会在这里工作.

任何解决方案

Aru*_*hny 9

您可以检查$.fn.live方法或jQuery.migrateWarnings对象的存在

<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>
Run Code Online (Sandbox Code Playgroud)