News for hackers. Stuff that matters.
Re:JavaScript Minification Benchmarks by arp242 on Saturday February 06, 2021 @07:00PM (#26051334)
I mostly stopped minifying my assets; as these benchmarks show, by far the biggest size reduction is in the gzip compression; for example lodash goes from 543k to 97k by just gzipping it, which can be reduced further to ~25k but that's actually quite a small saving compared to just the compression alone. And even on very slow connections 50k doesn't take too long to load.

The reason I don't really like doing it is that it obfuscates the code. Happened to discover a bug in production (which may not be easy to repro)? A lot easier to examine that if your files aren't minified. It also allows users to examine the scripts if they encounter bugs, which I've done on a number of occasions. It also simplifies the entire build process.

I know about source maps, but many people don't ship them and it all seems quite complicated for very little savings.

When I do minify, I usually just have a little script to remove the comments, which is often the biggest win with the smallest obfuscation.

I suppose that if you have a lot of JavaScript (>1M) it has more value, but in a lot of cases I see people minifying 100k scripts for little benefit "because that's just what you do".

My application ships a small 3K script people can add to their website which isn't minified on purpose (imagine being able to inspect what 3rd-party scripts do exactly!); IIRC minifying it would save 500 bytes or something, but I've had quite literally dozens of people ask me "why isn't it minified?!"

Re:JavaScript Minification Benchmarks by lxe on Saturday February 06, 2021 @07:20PM (#26051446)
You can always serve source maps for debugging purposes. They only get loaded once you actually open up devtools and start poking around. You can also configure stack traces to use the source maps, but I do understand the complexity increase in doing all this.
Re:JavaScript Minification Benchmarks by esperent on Sunday February 07, 2021 @03:14AM (#26053504)
It's not just about reducing the download time. Minified JS will parse faster - especially if using a minifier like Closure Compiler that has various heuristics to remove/simplify code.

I couldn't find any decent benchmarks to say exactly how much though. Of course for your 3kb script it's irrelevant, but a large web app may load a few mb of JS in which case it could make a big difference, especially on mobile devices.

Re:JavaScript Minification Benchmarks by taf2 on Saturday February 06, 2021 @07:32PM (#26051517)
I like minifying as an extra step to syntax check evaluate the code before it's shipped - very much like a compiler it can find some bugs...
Re:JavaScript Minification Benchmarks by arp242 on Saturday February 06, 2021 @07:47PM (#26051608)
You don't need minification for that as such; you can add it to your test step (and probably also run a more advanced static analysis tool while you're at it).

Also, I've also had minification introduce bugs; and while it's uncommon I'd rather not take the risk as these things are not easy to figure out.

Re:JavaScript Minification Benchmarks by winrid on Sunday February 07, 2021 @12:54AM (#26052994)
There is CPU overhead for the gzip, which could be a problem depending on scale/caching practices.