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?
The single script version is pretty neat. I wonder if there's a way to make it even easier on the developer. Hmm, there are probably a few little things, like hoisting the config var out of the run function, so it's at the top level of the IIFE.
What is the relationship between the script src in the single script version and the
destUrl
property in the config? That seems like it could be a point of confusion. My brain wants them to be the same ... or rather, it'd be great if I didn't have to specifydestUrl
at all unless I'm doing something really weird.