browserify / http-browserify

node's http module, but for the browser
MIT License
244 stars 110 forks source link

Use asynchronous module definition #1

Closed arnaud-lb closed 13 years ago

arnaud-lb commented 13 years ago

AsynchronousDefinition would allow to load the lib asynchronously in the browser:

    require('http', function(http) {
        // do stuff with http here
    });

http://requirejs.org/ and other asynchronous loaders support this.

In the library, this consists of wrapping all the code in a function that will be called by the loader when appropriate (after all dependencies are loaded, etc):

    define(['dependency1', 'dependency2', ...], function(dep1, dep2, ...) {
        var http;
        http.request = ...;

        return http;
    });
ghost commented 13 years ago

HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA.

ghost commented 13 years ago

Apologies, but this module is for browserify, hence the browserify in the title. I have no interest in the asynchronous require() style.

arnaud-lb commented 13 years ago

this module is for browserify, hence the browserify in the title

ok, missed that

I have no interest in the asynchronous require() style

Why ? I found it to really make development easier, just add a require and your modules are loaded. If an error occur during execution the browser reports the correct file/line number and all.

You can still pack a module and all its dependencies in a single file for production (requirejs provides a tool that does this), so the result in production is the same.

ghost commented 13 years ago

The point of this module and also of browserify is to emulate the node.js environment for browser code. Node.js doesn't use asynchronous require() and so this module doesn't either.