Hacker News new | ask | show | jobs
by tyingq 1620 days ago
How common is it to have your minifier change symbol/variable names to short ones?
8 comments

Pretty much all of them do it. You can’t minify keywords or literals, so that just leaves whitespace, which would be barely any minification at all.
Jsmin cited a typical 50% reduction without touching symbols, though perhaps that's an average that included removing comments.
I just popped open DevTools on an SPA I made using create-react-app with default settings. Sure enough the minified production JavaScript uses shortened variable names. This is default configuration for Webpack, which is pretty widely used throughout (and outside) the React ecosystem.

Interestingly you can still view the unminified source, since create-react-app generates source maps by default.

It is pretty common. The goal of the minifier is to reduce the size of the file, so taking the function names, variable names, etc and making them as short as possible works towardd that goal
Closure Compiler (for JavaScript) does it. With the SIMPLE_OPTIMIZATIONS [0] flag, it will rename parameters for—and variables local to—functions to save space.

[0]: https://developers.google.com/closure/compiler/docs/compilat...

I've seen some minifiers that can restructure your code... replace if{} with a ternary ?: operator or use boolean shortcutting to replace the whole conditional with a ||, and so on. It's supposed to never do anything that actually affects the logic, but that sort of stuff scares me.
Very common
That's literally what they are for.
For some context, it didn't used to be terribly common. There's a fair amount of minifying that you can do without touching symbol names, though obviously it doesn't help as much as shortening them. The old jsmin cited about 50% reduction, and it didn't touch any variable or class names.
It's actually pretty standard