Tool to Unminify / Decompress JavaScript

JavascriptCode FormattingMinifyCompressionUnminify

Javascript Problem Overview


Are there any command line scripts and/or online tools that can reverse the effects of minification similar to how Tidy can clean up horrific HTML?

(I'm specifically looking to unminify a minified JavaScript file, so variable renaming might still be an issue.)

Javascript Solutions


Solution 1 - Javascript

You can use this : http://jsbeautifier.org/ But it depends on the minify method you are using, this one only formats the code, it doesn't change variable names, nor uncompress base62 encoding.

edit: in fact it can unpack "packed" scripts (packed with Dean Edward's packer : http://dean.edwards.name/packer/)

Solution 2 - Javascript

Chrome developer tools has this feature built-in. Bring up the developer tools (pressing F12 is one way), in the Sources tab, the bottom left bar has a set of icons. The "{}" icon is "Pretty print" and does this conversion on demand.

UPDATE: IE9 "F12 developer tools" also has a "Format JavaScript" feature in the Script tab under the Tools icon there. (see Tip #4 in F12 The best kept web debugging secret)

enter image description here

Solution 3 - Javascript

Got it! JSBeautifier does exactly this, and you even have options for the auto-formatting.

Solution 4 - Javascript

Can't you just use a javascript formatter (http://javascript.about.com/library/blformat.htm) ?

Solution 5 - Javascript

In Firefox, SpiderMonkey and Rhino you can wrap any code into an anonymous function and call its toSource method, which will give you a nicely formatted source of the function.

toSource also strips comments.

E. g.:

(function () { /* Say hello. */ var x = 'Hello!'; print(x); }).toSource()

Will be converted to a string:

function () {
    var x = "Hello!";
    print(x);
}

P. S.: It's not an "online tool", but all questions about general beautifying techniques are closed as duplicates of this one.

Solution 6 - Javascript

If you have a Mac and TextMate - An easy alternative for formatting Javascript is:

  1. Open the file with Textmate.
  2. Click on > Bundles > JavaScript > Reformat Document
  3. Crack open a beer.

Solution 7 - Javascript

Most of the IDEs also offer auto-formatting features. For example in NetBeans, just press CTRL+K.

Solution 8 - Javascript

As an alternative (since I didn't know about jsbeautifier.org until now), I have used a bookmarklet that reenabled the decode button in Dean Edward's Packer.

I found the instructions and bookmarklet here.

here is the bookmarklet (in case the site is down)

javascript:for%20(i=0;i<document.forms.length;++i)%20{for(j=0;j<document.forms[i].elements.length;++j){document.forms[i].elements[j].removeAttribute(%22readonly%22);document.forms[i].elements[j].removeAttribute(%22disabled%22);}}

Solution 9 - Javascript

I'm not sure if you need source code. There is a free online JavaScript formatter at http://www.blackbeltcoder.com/Resources/JSFormatter.aspx.

Solution 10 - Javascript

Try this one, with code coloration:

http://labs.swelen.com/tools/javascript/beauty.html

Solution 11 - Javascript

click on these link for JS deminification. That will install on FF as extension that help you in debugging js at runtime.

https://addons.mozilla.org/en-US/firefox/addon/javascript-deminifier/eula/141018?src=dp-btn-primary

Solution 12 - Javascript

Similar to Stone's answer, but for Windows/.NET developers:

If you have Visual Studio and ReSharper - An easy alternative for formatting Javascript is:

  • Open the file with Visual Studio;
  • Click on ReSharper > Tools > Cleanup Code (Ctrl+E, C);
  • Select "Default: Reformat code", and click OK;
  • Crack open a beer.

Solution 13 - Javascript

Despite its miles-away-from-being-pretty interface, JSPretty is a good, free and online tool for making javascript source codes human-readable. You can enforce your preferred type of indentation and it can also detect obfuscation.

Solution 14 - Javascript

If one is in JS possibility of using Firefox is more. And if its Firefox add on is for rescue. Following one is particularly useful.

https://addons.mozilla.org/en-US/firefox/addon/phoenix/

Solution 15 - Javascript

http://prettydiff.com/?m=beautify">Pretty Diff will beautify (pretty print) JavaScript in a way that conforms to http://jslint.com/">JSLint</a> and http://jshint.com/">JSHint</a> white space algorithms.

Solution 16 - Javascript

Wasn't really happy with the output of jsbeautifier.org for what I was putting in, so I did some more searching and found this site: http://www.centralinternet.com.br/javascript-beautifier

Worked extremely well for me.

Solution 17 - Javascript

http://unminify.appspot.com/ Great tools for unminify javascript and json

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndy FordView Question on Stackoverflow
Solution 1 - JavascriptFabien MénagerView Answer on Stackoverflow
Solution 2 - JavascriptJon AdamsView Answer on Stackoverflow
Solution 3 - JavascriptRobin RodricksView Answer on Stackoverflow
Solution 4 - JavascriptJancoView Answer on Stackoverflow
Solution 5 - JavascriptkatspaughView Answer on Stackoverflow
Solution 6 - JavascriptStoneView Answer on Stackoverflow
Solution 7 - Javascriptgou1View Answer on Stackoverflow
Solution 8 - JavascriptMottieView Answer on Stackoverflow
Solution 9 - JavascriptJonathan WoodView Answer on Stackoverflow
Solution 10 - JavascriptSwelen TeamView Answer on Stackoverflow
Solution 11 - JavascriptsanjeevView Answer on Stackoverflow
Solution 12 - JavascriptC. Augusto ProieteView Answer on Stackoverflow
Solution 13 - JavascriptFarshidView Answer on Stackoverflow
Solution 14 - JavascriptAnil NamdeView Answer on Stackoverflow
Solution 15 - JavascriptaustincheneyView Answer on Stackoverflow
Solution 16 - JavascriptDoyle LewisView Answer on Stackoverflow
Solution 17 - JavascriptBui Dinh NgocView Answer on Stackoverflow