I understand how browserify works, maybe I didn't clarify well enough.

Yes, you don't have to inject moduleZ into moduleA, B and C if you put them
all in the same file and load that js file upfront.

This is not scalable though. If my entire site has 200kb of JS throughout
the entire site, requiring users to download all 200kb upon page load is
well, non-sensical.

You should modularize your code so that you only require the JS for
specific pages/functionality when you actually need it.

This is accomplished via something like:

require("someFile", function(someModule){

});

Browserify does not handle this use case at all. Yes, if you want to concat
and minify all your js into a single file and load that file everywhere,
sure, go right ahead, but you're doing it wrong.

Taka

On Thu, Feb 9, 2012 at 2:27 PM, Phoscur <[email protected]> wrote:

>  I think you haven't actually understood how browserify/browserbuild work:
> 1. load source files
> 2. wrap a function around them
> 3. concat all of them together and add a custom require() emulating node's
> require
> 4. instead of many script tags, insert one with the big file
>
> Now when moduleA requires moduleZ, the moduleZ function wrapper is
> executed exactly once when it's needed the first time (lazyload). Why
> should the call to function wrapper be asynchronous in this case??
>
> Using browserify, you have to inject moduleZ into moduleA, moduleB and
> moduleC. If moduleZ is 30kb of javascript, this is a huge issue.
>
> inject what? What do filesizes matter here?
>
>
> Am 09.02.2012 23:11, schrieb Taka Kojima:
>
> It's not really AJAX, it's just loading in the js files by injecting
> <script> tags into the DOM.
>
>  require() in it's synchronous form makes sense in the context of node,
> it does not in the context of the browser.
>
>  Say you have moduleA, moduleB and moduleC and they all require moduleZ.
>
>  Using browserify, you have to inject moduleZ into moduleA, moduleB and
> moduleC. If moduleZ is 30kb of javascript, this is a huge issue.
>
>  This is just one of the reasons why taking the async approach works
> better, it does what node does synchronously, a synchronously. require()
> accepts a string, tries to map that path to a file, includes that file,
> etc. in the process of doing this, it caches that js file. Thus, calling
> require("foo") 100 times, does not have the overhead of require("foo") x
> 100.
>
>  You can not get require("foo") working in the browser the same way that
> node implements it. You can however, get an async approach to this problem
> implemented in node. You need some way for the browser to resolve "foo" to
> an actual file, load that file, and upon loading that file, invoke a
> callback function.
>
>  This is a problem that RequireJS, MinionJS and dojo all handle and this
> is the right approach the problem.
>
>  Browserify is a cool project, but it's usefulness ends as soon as you
> step into real world applications.
>
>  Taka
>
> On Thu, Feb 9, 2012 at 1: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
>>
>
>  --
> 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
>

-- 
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