meenie / munee

Munee: Standalone PHP 5.3 Asset Optimisation & Manipulation
https://munee.herokuapp.com/
MIT License
833 stars 92 forks source link

How can I add JS obfuscation? #25

Closed dfb243fda closed 11 years ago

dfb243fda commented 11 years ago

I want to obfuscate JS for minify, for example input: function one(first, second) { alert(first + second); } output: function one(a, b) { alert(a, b); } Is it possible to do that?

meenie commented 11 years ago

If you use the packer=true option, then it will run the javascript through Packer by Dean Edwards. Will that work for you?

dfb243fda commented 11 years ago

That will not work for me, because it doesn't minify code, code will be bigger after this packer. I just wanted to shrink variables in functions, but this packer do this: input: function func(first_arg, second_arg) { alert(first_arg + second_arg); } output: eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('2 4(1,0){3(1+0)}',5,5,'second_arg|first_arg|function|alert|func'.split('|'),0,{}))

And I want just: function func(e,t){alert(e+t)}

meenie commented 11 years ago

Ahh, I see. The php library I'm using doesn't actually support obfuscation. If you can recommend one that does, let me know and I will drop it in as a replacement.

Closing this off now, but let me know if you have any more questions.

Cheers, cody

dfb243fda commented 11 years ago

Thank you! I have tried to use https://github.com/nicolas-grekas/JSqueeze with your library, it works well (shrinks variables)

meenie commented 11 years ago

Did you write it into my library as another filter? Or using it side by side? If you wrote it in as a filter, submit a pull request and I'll have a look :+1:.

Glad you found a solution!

dfb243fda commented 11 years ago

I wrote filter "minify2" and submit a pull request to you

kiwifly commented 10 years ago

Hi, Did this function write into library? I also want this function, or I do this by myself?