data-main is another way to make the initial call to require your application. To illustrate ... this:
<script data-main="scripts/main" src="scripts/require.js"></script>
equivalent to this:
<script src="scripts/require.js"></script> <script>require(["scripts/main"])</script>
Two forms are asynchronous. That is really all that is needed. Considerations about how many entry points you have or where the RequireJS configuration will be located are completely orthogonal to using data-main . In other words, these considerations play a role in using data-main to the same extent that they play a role in using require(["scripts/main"]) .
Part of the documentation you cite just obscures things, noting that the script loaded with data-main creates a script element in the head element with a set of async attributes, because this is no different than loading any script through RequireJS. Each script loaded by RequireJS will have a script element created for it in head and having an async attribute.
It is customary to use data-main for applications that have only one entry point, and put the RequireJS configuration in the module specified in data-main , but this is not required by any means. For example, this is a perfectly acceptable use:
<script> require = { </script> <script data-main="scripts/main" src="scripts/require.js"></script> <script> require(["foo"], function (foo) { foo.something(); }); </script>
The configuration is provided by RequireJS, installing require in a global space before loading RequireJS. (If require is specified before RequireJS is loaded, the value of require will be taken as its configuration.) In addition to launching the application when loading scripts/main , this code also loads foo and calls a method on it: two entry points.
Louis source share