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?
I prefer the clean single line script (as per RequireJS), but I agree with @briancavalier that
data-curl
should be more adaptable likedata-amd
rather than library specific.Also, is 'single-script-run' something the developer has to write out every time? Looks like an arse ache to me (sorry). But I'm comparing this example to RequireJS which i only need to specify data-main attribute and inside my loaded script I have my standard config obj and just start making
require()
calls as necessary. RequireJS is much easier for a developer to get started compared to the above example which needs 3 functions + conditional check.