In both cases below, ID
is the exports object of the "id"
module.
require.ensure(["id"], function (require) {
var ID = require("id");
})
- In this example, the
"id"
module does not need to be loaded before executing this module. Because it uses therequire("id")
syntax, it is not simple to distinguish it from a dependency that must be preloaded.
require.async("id", function (ID) {
}, function (error) {
});
- does not accept multiple identifiers. The presumption is that it will be more common and usable for the loaded module to statically depend on anything you would be tempted to import in the same async call. If this presumption does not pan out (in my own use, it has), it is easy enough to extend this specification with spread/rest (variadic) arguments.
What are your thoughts on just passing the module exports of 'id' to the callback instead of
require
? I find having to duplicate the ID in two places to be awkward, and this sort of call should only have a small set of IDs passed to it.