3 ms·
This whole page is weirdly similar to a project I did, for the same purpose: https://evmar.github.io/js-min-bench/ https://evmar.github.io/js-min-bench/ What
by evmar 6y ago
This whole page is weirdly similar to a project I did, for the same purpose:
https://evmar.github.io/js-min-bench/ https://evmar.github.io/js-min-bench/
What I discovered there is that the best minification is one where you just produce an empty file -- it's 0 bytes of output and extremely fast.
And if you say "wait, I have have the additional requirement that you didn't break the code in the original file, obviously!", you then must define what exactly "break" means in that requirement-- for example, it could be that some user requires that someFunction().toString().charAt(10) == 'a', in which case even removing whitespace counts as breakage.
You might think the above is just being overly pedantic or pathological, but it demonstrates a principle that actually ends up mattering, which is that you can't evaluate a minifier unless you define what a successful minification even means. Particularly in the case of more advanced transformation.
I went into it more in this post:
http://neugierig.org/software/blog/2019/04/js-minifiers.html http://neugierig.org/software/blog/2019/04/js-minifiers.html
- jiofih 6y agoSorry but what do you mean by “weirdly similar”? It’s a benchmark of minifiers against popular libraries, what’s the creative part?
- yoz-y 6y agoI guess a reasonable requirement for a momifier would be that the test suite passes 100% of tests after minification.
- emptysea 6y agoI think your example should instead be: someFunction.toString().charAt(10) == 'a' so you're getting the function's string representation, not its return value Also I've never even considered that minifiers can break your code. To be safe it seems you either need to run minification during test & dev or setup some linting to ban features that could break during minification.
- evmar 6y agoYou are totally right, thanks for catching my mistake. My blog post linked above goes more into the consequences -- ideally you'd formally define what the allowable language subset is.
- bmm6o 6y agoYou're not wrong, but if your code breaks when you apply the simplest refactorings you probably aren't thinking about minifying your code. And while Javascript does let you put yourself in that position, I've never seen it in production code. Angularjs dependencies are a notable exception, and have a backup mechanism.
- fnordsensei 6y agoExcept yours include results for Closure in advanced mode, which is enlightening.