Consider the following page:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
</head>
<body>
<script data-main="app" src="require.js"></script>
</body>
</html>
How can i use jQuery as a dependency for RequireJS modules when it’s not loaded with RequireJS? I know jQuery exposes itself as a global AMD module, so i should be able to add it as a dependency, but i’m not quite sure how to.
I would like to be able to do the following:
require(['jquery'], function() {
console.log('success')
});
And if jQuery has not yet finished loading, it should wait for it to complete, and then continue. Is this possible to do?
Load jQuery second, RequireJS first. Run your main module when both are loaded.
jQuery will NOT register itself as AMD module if it does not see
define.amdfloating around. The only way to make it register itself properly is to load RequireJS before jQuery.