The most authoritative definition of how some software works is to examine the source. Minifying JavaScript makes for faster downloads and has an extra added benefit of obfuscating your source code. Fear not, you can un-minify.
There are online JavaScript beautifiers which are fine for trivially small files. Once you try to de-minify any substantial amount of source, you don’t want to be trying to copy / paste large files through the clipboard. So, you want a command-line tool. I Googled around and found some recipes that almost worked, but not quite. So, here’s a recipe that works at the time of writing (November 2014) for Ubuntu.
Install Rhino, an environment that will allow you to execute JavaScript from the command line:
sudo apt-get install rhino
Go to your directory where your local scripts, in my case:
cd ~/src/scripts
Then get the latest JavaScript beautifier from jsbeautifier.org:
wget http://jsbeautifier.org/js/lib/beautify.js
Open beautify.js up in your favourite text editor and add the following right at the end:
print( global.js_beautify( readFile( arguments[0] )));
Now create a new file to invoke the beautifier, let’s call it beautifyjs
:
#!/bin/sh
java -cp /usr/share/java/js.jar org.mozilla.javascript.tools.shell.Main ~/src/scripts/beautify.js $*
Now just make it executable and you’re cooking with gas:
chmod +x beautifyjs
I shouldn’t need to tell you this, but just in case you haven’t worked it out, here’s how you use it:
./beautifyjs myMinifiedFile.js