There are a couple of things that bug me about RequireJS's data-main method of single-script loading:
<script src="js/requirejs/require.js" data-main="app/main.js"></script>
- the built file (bundle) must be named "require.js". WAT.
- it just seems backwards.
data-main
does not follow w3c recommendations since it's not name-spaced.
Here are two examples of what came to mind when I spent a few minutes thinking about alternatives. The first one is an example of a double-script bootstrap. This is a great alternative if loading curl.js from a CDN since the scripts will load in parallel.
The second example uses a single script element. This is a great alternative if you decide to bundle curl.js into run.js. The problem is that there's a lot of boilerplate in run.js. However, the example run.js compresses down to 500 bytes (333 gzipped). Not too bad?
@Integralist: I see what you're saying. 90% of single-script-run.js is boilerplate that the dev doesn't have to touch. We could easily hoist the curl config object out to the global scope (declared in the html page). Gonna try that next.
I sorta like the
data-amd
idea. Maybe namespace it like Brian says (w3c recommends, too). But it also seems precocious. We're assuming that RequireJS and the rest of the AMD world will agree with our way of using that attribute.