RequireJS not working in IE9

2019-06-20 06:01发布

问题:

I'm experiencing a fairly peculiar behavior - my RequireJS modules seem to be not initializing and running at all under IE9:

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

However, whenever I fire up IE9's developer tool, and reload the page, the modules will be running fine just as they should in Firefox/Chrome/Safari/etc. Cleaning browser cache and closing the developer tool in IE9 will render the JavaScript not running entirely again.

Another way to kick-start the execution of the RequireJS modules is to add a synchronous script calling before it:

<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>

It would appear that the reason of the weird behavior may either be:

  • Something went wrong with RequireJS' async loading
  • Something went wrong that caused scripts to launch before $.ready()

Why the developer tool can kick-start the execution really baffled me, though.

Looking for a full explanation to the phenomenon and how to solve it.

回答1:

Found the answer: console is undefined in IE9 when dev tool is not opened, but you never get to see this error since the tool's console requires a page reload to start working.

More details here: https://github.com/jrburke/requirejs/issues/488