Strip code

41 views
Skip to first unread message

Kevin Ingwersen

unread,
May 15, 2015, 9:51:31 AM5/15/15
to nod...@googlegroups.com
Hey.

When working with C++ stuff, I usually see myself running the stirp over the resulting binary to press down the filesize on a Release target. However, there seems to be no such thing for JavaScript.

What I am actually wanting to do, is to shrink jQuery. It has tons, and tons, and tons of stuff inside of it, and it is like so much, I only use 10% of it, when it comes to it.

So I was looking for some tool that strips unused code…

Since I am using WebPack, I get all the code, transpiled, compiled, and whatever, into a single target. This target, I can edit using a plugin. (Well, could. Plugin docs are still sparse.)

Do you know a tool that does dead code elimination, that actually works? I am aware of refs and such. Like:

var getElem = document.getElementById;
var cont = getElemen(…);

… but there must be a way. Somehow, at least I hope so.

Kind regards, Ingwie.

Aria Stewart

unread,
May 15, 2015, 9:57:41 AM5/15/15
to nod...@googlegroups.com, ingwi...@googlemail.com


On Friday, May 15, 2015 at 9:51:31 AM UTC-4, Ingwie Phoenix wrote:
Hey.

When working with C++ stuff, I usually see myself running the stirp over the resulting binary to press down the filesize on a Release target. However, there seems to be no such thing for JavaScript.

What I am actually wanting to do, is to shrink jQuery. It has tons, and tons, and tons of stuff inside of it, and it is like so much, I only use 10% of it, when it comes to it.

So I was looking for some tool that strips unused code…

That's actually not analogous to strip(1), since all strip does is remove debugging -- roughly equivalent to stripping source maps from javascript.

What you need is dead code elimination, much like a whole-program link-time optimizer can do for C.

Google Closure Compiler does some of this; there may be others, though dead code detection and elimination is definitely something still being studied. Sometimes there are obvious cases, sometimes there are not. Detecting those edge cases are the hard continuing research.

Aria
Reply all
Reply to author
Forward
0 new messages