Are there any 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 (like with compression or packing) should theoretically not be an issue.
Source: Tips4all
You can use this : http://jsbeautifier.org/
ReplyDeleteBut 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/)
Chrome developer tools has this feature built-in. Bring up the developer tools (pressing F12 is one way), in the Scripts tab, the bottom left bar has a set of icons. The "{}" icon is "Pretty print" and does this conversion on demand.
ReplyDeleteUPDATE: 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)
Can't you just use a javascript formatter (http://javascript.about.com/library/blformat.htm) ?
ReplyDeleteMost of the IDEs also offer auto-formatting features. For example in NetBeans, just press CTRL+K.
ReplyDeleteIn 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.
ReplyDeletetoSource 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.
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.
ReplyDeleteI 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);}}
I'm not sure if you need source code. There is a free online JavaScript formatter at http://www.blackbeltcoder.com/Resources/JSFormatter.aspx.
ReplyDeleteTry this one, with code coloration:
ReplyDeletehttp://labs.swelen.com/tools/javascript/beauty.html
If you have a Mac and TextMate - An easy alternative for formatting Javascript is:
ReplyDeleteOpen the file with Textmate.
Click on > Bundles > JavaScript > Reformat Document
Crack open a beer.
click on these link for JS deminification. That will install on FF as extension that help you in debugging js at runtime.
ReplyDeletehttps://addons.mozilla.org/en-US/firefox/addon/javascript-deminifier/eula/141018?src=dp-btn-primary
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.
ReplyDeletehttps://addons.mozilla.org/en-US/firefox/addon/phoenix/