bundle-collapser icon indicating copy to clipboard operation
bundle-collapser copied to clipboard

Difference from intreq?

Open callumlocke opened this issue 11 years ago • 1 comments

What is the relationship between this and intreq? Does this replace intreq?

It would be good to link to this from that readme, and from the browserify readme in fact... It's frustrating to think how much time I've spent on this problem over the last few months, not knowing this module existed!

callumlocke avatar Nov 25 '14 10:11 callumlocke

This is a very unscientific unofficial answer, but maybe it'll be useful for people of the future:

Both bundle-collapser and intreq replace require('path/to/file') with require(2), where 2 is some numeric ID.

The difference is that with bundle-collapser those IDs appear to be global, while with intreq those IDs are local to each module.

That means that, with intreq, each module gets this little header:

3:[function(require,module,exports){...},{"1":52,"2":68,"3":81,"4":127}]

But with bundle-collapser, that's empty, as it appears the IDs are globally known:

3:[function(require,module,exports){...},{}]

So I don't know why you would choose to use intreq over bundle-collapser now, and I'm kinda surprised that bundle-collapser isn't implemented in terms of intreq. I guess intreq is just an old deprecated choice, but it would be good to get some official word/warning on the readme there.

Removing the header makes a noticeable-but-not-huge difference to the final file size. Here's an anecdote for trello.com, a ~40kloc codebase split across ~300 files, after uglification:

        -------------------
       | bc      | intreq  |
 ------|---------|---------|
| raw  | 1767009 | 1777165 |
| gzip | 398792  | 405014  |
 --------------------------

The bundle-collapser output is about 1.5% smaller than the intreq output.

Some numbers pre-uglification, though I don't think it's that useful:

        -------------------
       | bc      | intreq  |
 ------|---------|---------|
| raw  | 2993571 | 3008533 |
| gzip | 581306  | 590906  |
 --------------------------

I kind of expected bundle-collapser to compress better, as you see code like this repeated a lot:

var $ = require(52);

Instead of intreq's:

var $ = require(2); // in one module
var $ = require(4); // in another

But it appears that it doesn't make a real difference, and minification would probably ruin that anyway.

ianthehenry avatar Mar 04 '15 18:03 ianthehenry