Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How important is using tiny variable names in Javascript?

It seems like, for many javascript widgets, the authors have made a conscious effort to use tiny variable names. For example:

// Instead of...
this.mousePositions = new Array();
// they use...
this.mp = new Array();

My question is this: how important is this in terms of reducing overall javascript file request size? I'm working on releasing a javascript widget to the public, which, after being minified, is about 2.8KB. However, because the main advantage of this plugin is how lightweight it is, does anyone have experience with whether it's worth it to go through and switch out all of the sensical variable names that I used with these new, tiny variable names? It just seems like the code is so much less readable that way and it's going to be much harder to maintain.

Thanks for your help!

Charlie

like image 266
zeptonaut Avatar asked Oct 29 '10 20:10

zeptonaut


1 Answers

How important? not really unless they're used all over the place, delivering your scripts via gzip compression negates most of the name byte-cost there.

But why not have the best of both words? Use descriptive names when developing (why punish yourself?), then minify your scripts as part of the build process to get small compact names for production code, and a minimal-size transfer to the user.

like image 86
Nick Craver Avatar answered Sep 19 '22 13:09

Nick Craver