RequireJS无法在IE9中运行

gsk*_*lee 6 javascript internet-explorer asynchronous internet-explorer-9 requirejs

我遇到了一种相当奇特的行为 - 我的RequireJS模块似乎没有在IE9下初始化和运行:

<head>
    ...
    <script data-main="/static/js/main" src="/static/js/libs/require.js"></script> // Seems to be not running at all.
</head>
Run Code Online (Sandbox Code Playgroud)

但是,每当我启动IE9的开发人员工具并重新加载页面时,模块就会像在Firefox/Chrome/Safari /等中一样正常运行.清理浏览器缓存并关闭IE9中的开发人员工具将导致JavaScript无法再次完全运行.

另一种启动RequireJS模块执行的方法是在它之前添加一个同步脚本:

<head>
    ...
    <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script> // Add any synchronous script calling here and the module below will execute fine.
    <script data-main="/static/js/main" src="/static/js/libs/require.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)

似乎奇怪行为的原因可能是:

  • RequireJS的异步加载出了问题
  • 出现问题导致脚本在$ .ready()之前启动

但是,为什么开发人员工具可以启动执行实际上让我感到困惑.

寻找对该现象的完整解释以及如何解决它.

gsk*_*lee 5

找到了答案:consoleundefined在IE9的时候没有打开开发工具,但你永远不会看到这个错误,因为该工具的控制台需要重新加载页面开始工作.

更多细节:https://github.com/jrburke/requirejs/issues/488