1

I have some questions regarding js file based on Jquery :

1) Which algorithm is used to minify js files?
2) Is it easy to implement that algorithm programatically?
3) Is minifying js is reversible process? i.e. Can we able to get original js file from minified js file? If yes, Is it the same algorithm to unminify it?

Please help.

0

2 Answers 2

3
  1. To Minify JS:

http://dean.edwards.name/packer/
http://crockford.com/javascript/jsmin
http://code.google.com/intl/pl/closure/compiler/
http://developer.yahoo.com/yui/compressor/
http://ajaxmin.codeplex.com/

  1. You can write algo for minify your js by yourself but it would be better to use any of the above tools for this. Reason is that they are already providing good minification and they are time-tested

  2. Minifying is a reversible process. Since browsers can only understand javascript, these algos need to be reversible. and so others can also reverse the minification.

Sign up to request clarification or add additional context in comments.

1 Comment

Well, it is not exactly reversible. Some things are lost, such as variable names, function names, and comments. So a beautifier can make it similar in terms of coding standards, but it will almost always be much less readable.
2

3: Minifying is not reversible in the typical meaning of the word. A minified program is just required to behave identically to the un-minified program (not counting execution time).

You can't reproduce the layout as it was: white spaces or the comments, the actually used variable names, nor parenthesis. It's also possible that some minifiers do constant evaluation (i.e. 1.0*(1.0+1.0) could become 2. or 2); Can't reproduce removed dead code. (ie. this block is removed)

if (0==1) { // TODO: why isn't this working?
  i++
  alert('');
}

2: No, it's not easy at all

Even the very first stage of removing white spaces and comments could be beyond the final assignment of programming 101.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.