FWIW, we have a module that supports browser side requires. I provided
it as a streamline "goodie" about a year ago. It works the following
way:

* The server analyzes the require dependencies when the client
requests the main module of a page. The server returns the script and
all dependencies as a single multipart message. So the client gets all
its initial scripts in one roundtrip (with an etag so that client can
cache it and get a 304 next time).

* If the client needs to load more modules incrementally, it sends an
XHR request for the module with an indication of the "known" module(s)
that it had requested before (only the top level modules, not their
dependencies). The server computes the dependencies of the requested
module and subtracts the dependencies of the "known" modules. This
gives a list of "missing" modules that the server sends to the client
as a single multipart document.

On the client side, this is packaged as a simple require.js file that
takes care of all the communication issues and provides a very simple
API: the usual 'require' for dependencies + a 'require.async' for on-
demand loading of additional modules.

The implementation does not handle all the subtleties of module paths
(for example reading package.json to get the main script of a package)
but it does a job that is good enough for us. Overall, it is very easy
to use, it does not require any build step and performance is great.

https://github.com/Sage/streamlinejs/tree/master/lib/require

Bruno



On Feb 9, 10:35 pm, Phoscur <[email protected]> wrote:
> Then do not load code via ajax.
>
> Am 09.02.2012 22:18, schrieb Mark Hahn:
>
>
>
>
>
>
>
> > >  What exactly the problem with using node's synchronous approach in
> > the browser?
>
> > Node loads the module quickly from the disk.  Loading over an ajax
> > request is much slower.
>
> > --
> > Job Board:http://jobs.nodejs.org/
> > Posting guidelines:
> >https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> > You received this message because you are subscribed to the Google
> > Groups "nodejs" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to