We all work hard when it comes to javascript and unfortunately there is no way to just hide the js in the browsers, but nevertheless we don't want other people to immediately be able to copy what we have accomplished in hours of work. When I look at Facebook script tags, its just a spaghetti-load of single letter variables and functions that no one could decipher in a jiffy. Is there something like a program of script that just "anonymizes" / "deciphers" / "encodes" my js so noone can really immediately see whats going on?
Example (be it far from perfect and full of errors):
function convertTimeToString(time) {
var seconds = 0;
var minutes = 0;
if(time % 60 >= 10) {
seconds = time % 60;
else {
seconds = "0" + time % 60;
}
minutes = Math.floor(time/60);
return minutes + ":" + seconds;
}
becomes something like this
function s(t){var a=0;var b=0;if(t%60>=10){a=t%60;}else{a="0"+t%60;}b=Math.floor(t%60);return b+":"+a;}
I guess you see the difference, it would take a good js coder a bit more time to make sense out of what this script is actually doing. Any ideas how to do it automatically?
-
some obfucators are available but there're some de-obfuscators working fine... so why waste time to pack some javascript code and make the code execution slower? (packed code must be EVALuated) If someone want to copy your js, he will be able to do it anyway (and if happens, it usually means your that code is good)Fabrizio Calderan– Fabrizio Calderan2012年07月03日 08:31:44 +00:00Commented Jul 3, 2012 at 8:31
-
1Personally, I find the free copying and modification of javascript to be one of the key benefits of the html/js model. You are free to pick up anything anyone else has done; it promotes code reuse, sharing, etc. Frankly your minified version would be as readable as the original with an auto-indent, or even more since there's less to read. What have you got to gain from obfuscation, except degrading your own debugging?Phil H– Phil H2012年07月03日 08:32:22 +00:00Commented Jul 3, 2012 at 8:32
-
2Client-side code is meant to be open, like the web. You minify code to make it smaller not to "protect hard work".elclanrs– elclanrs2012年07月03日 08:32:54 +00:00Commented Jul 3, 2012 at 8:32
-
note that unobtrusive is only regarding separation of concerns, i.e. keeping the logic (JavaScript) departed from the markup (HTML).Eliran Malka– Eliran Malka2012年07月03日 08:38:13 +00:00Commented Jul 3, 2012 at 8:38
2 Answers 2
Use a minifier like YUI Compressor or UglifyJS
Comments
Try JSMin for a start:
JSMin does not obfuscate, but it does uglify.