2 ms·
There are a lot of misconceptions about CommonJS modules in the browser. You've touched on most of them. Of course you need a loader or packaging script, any m
by tlrobinson 16y ago
There are a lot of misconceptions about CommonJS modules in the browser. You've touched on most of them.
Of course you need a loader or packaging script, any module system that wants to handle dependencies will. Script tags are inadequate for anything except the simplest cases.
You can load your modules asynchronously, even though the main "require()" API is synchronous. Simply load the modules and their dependencies up front before executing them. This is what we've been doing for years in the Objective-J loader, and several CommonJS browser loaders already do it.
Also, I believe "require.async(id, callback)" is part of the spec now too, and they're working on an "async module definition" spec, which allows loading in script tags with minimal boilerplate ("require.def(id, function() { /module/ })")