Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJS not working in IE9

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.

like image 818
gsklee Avatar asked Oct 05 '12 12:10

gsklee


People also ask

How do you use RequireJS?

Syntax. define(['module1', 'module2'], function (module1, module2) { //define the module value by returning a value return function () {}; }); You can pass a list of module names when you define a module and RequireJS can be used to retrieve these modules before executing the module.

How add RequireJS to HTML?

To include the Require. js file, you need to add the script tag in the html file. Within the script tag, add the data-main attribute to load the module. This can be taken as the main entry point to your application.

What is RequireJS config?

Advertisements. RequireJS can be initialized by passing the main configuration in the HTML template through the data-main attribute. It is used by RequireJS to know which module to load in your application. For instance − <script data-main = "scripts/main" src = "scripts/require.js"></script>

Is RequireJS a framework?

RequireJS is a basic loader, which is used to loads the JavaScript files, it is a framework to manage dependencies between JavaScript files, and in modular programming, all the functionality divides in different modules, so RequireJs is a best tool to assemble different JavaScript files from different modules by which ...


1 Answers

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

like image 99
gsklee Avatar answered Sep 19 '22 12:09

gsklee