6

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

<head>
    ...
    <script data-main="/static/js/main" src="/static/js/libs/require.js"></script> // Seems to be not running at all.
</head>

但是,每当我启动 IE9 的开发人员工具并重新加载页面时,这些模块都会像在 Firefox/Chrome/Safari/etc 中一样正常运行。在 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>

看起来奇怪行为的原因可能是:

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

不过,为什么开发人员工具可以启动执行确实让我感到困惑。

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

4

1 回答 1

5

找到了答案:当开发工具未打开时在 IE9 中,但您永远不会看到此错误,因为该工具的控制台需要重新加载页面才能开始工作consoleundefined

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

于 2012-10-10T07:37:57.307 回答