Question

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.

Was it helpful?

Solution

  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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top