Re:JavaScript Minification Benchmarks
by emptysea on Saturday February 06, 2021 @08:30PM
(#26051805)
I think your example should instead be:
someFunction.toString().charAt(10) == 'a'
so you're getting the function's string representation, not its return valueAlso 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.
You 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.
You'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.
Sorry but what do you mean by “weirdly similar”? It’s a benchmark of minifiers against popular libraries, what’s the creative part?
I guess a reasonable requirement for a momifier would be that the test suite passes 100% of tests after minification.
Re:JavaScript Minification Benchmarks
by fnordsensei on Sunday February 07, 2021 @04:08AM
(#26053714)
Except yours include results for Closure in advanced mode, which is enlightening.
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