Portal Home > Knowledgebase > Articles Database > how can i encode javascript ??


how can i encode javascript ??




Posted by alfares, 05-29-2007, 11:44 PM
hi all i have a javascript file and i want to encode it or at least make it hard for anyone to understand is there a way for this thanks alot

Posted by HostSentry, 05-30-2007, 01:31 AM
Well the first thing to realize about encoding javascript is that it is easily decoded. In fact, it is required to be easily decoded since your browser does it in the first place. Encoding javascript is about as silly as adding a no right click script to your picture gallery. You can obviously make the javascript less easy to read/understand. A javascript file that has comments is less easy to understand than one that has comments. Another easy change is to make all of the function names things like "a","b", or "c". This will make it entirely difficult to read, but still not impossible to understand. You just have to realize that your browser needs to be able to understand (might be a bad word for that) what is going on, so if it is able to do that, it is not impossible for someone else to be able to do that. Why do you want to encode your javascript anyway?

Posted by arkin, 05-30-2007, 02:34 AM
There are PHP Javascript encoders that you can download which sites such as mootools.net and various others use. Not only do they make the file look ridiculous and all of the above mentioned things above, they actually decrease the size. Hope this helps.

Posted by WO-Jacob, 05-30-2007, 04:39 AM
Important note: They are not encoders. They are obfuscators. You could 'encode' javascript by making a 3rd party addon that has to be loaded into the browser that would turn actually encoded files into JS that the browser could use, but short of that, all you can do is obfuscate. And the whole decreasing file size thing is a bonus, and helps to the obfuscation as well. It will remove all natural formatting and such, which works fine as long as you remember to keep a development copy

Posted by tsj5j, 05-30-2007, 05:26 AM
I think he knows that, as he mentions "or at least makes it hard for anyone to read".

Posted by WO-Jacob, 05-30-2007, 05:40 AM
Just figured I'd cover the bases. Never hurts to include too much information, but too little can be disastrous.

Posted by mwatkins, 05-30-2007, 08:46 AM
Instead of trying to obfuscate the source, why not leave it perfectly readable, open source it, and put a copyright notice in it. Then you'll get a little notoriety (assuming the code is remarkable in some way). Instead of trying to hide the code, why not encourage people to use it?

Posted by WO-Jacob, 05-30-2007, 08:51 AM
Because not everyone is ok with people simply reusing their work without renumeration? But that's another thread...

Posted by mwatkins, 05-30-2007, 10:11 AM
I find that newbies tend to have an overly inflated perception of the value of their code, and focus on obfuscation and code encryption rather than writing better code. A well written piece of code can be a good calling card, drumming up more business. My rhetorical question "why not leave it open" was intended to suggest an option the OP or other readers might not have considered before... that making these open with an unrestricted license that requires the original author be identified can actually be a good thing for business. Whether or not it makes sense for the OP is another matter, but should be considered.

Posted by nnormal, 05-30-2007, 10:29 AM
one thing to be aware of if you are going the obfuscation route is that many obfuscation routines cram everything on one line so make sure you don't leave off any ;s (which is perfectly legal in JS as line endings are interpreted as ; )

Posted by alfares, 05-30-2007, 06:22 PM
thanks all i have a javascript for a popup that i dont want to speard all over the net, thats why i need to at least make it hard to be read because you can download the script if you know its URL this is one javascript file http://www.alaqwa.com/scriptopen.js and if anyone could do me a favor and try to make it hard to be read, at least hid the URL of the other file that it read from phpadsbanner +='document.write(\'<'+'script src="cont.js"> and dont forget to tell me how thanks all

Posted by arkin, 05-30-2007, 09:31 PM
I was aware, but thank you WO-Jacob. Don't want to confuse anyone here.

Posted by mwatkins, 05-31-2007, 01:40 PM
If simply making it hard to read is sufficient, you could use Dojo's shrinksafe. Some assembly required. http://dojotoolkit.org/docs/shrinksafe

Posted by Dark Light, 05-31-2007, 02:01 PM
ionCube offers a free HTML obfuscating PHP system where you load the ionCube loaders on your website (either through runtime loading or in php.ini) and then include their HTML obfusication PHP script on your server. This will this obfusicate your HTML output including JavaScript. This is fine if you do not mind having right click, copy text, and your entire HTML + JavaScript obfusicated. One issue is that your JavaScript has to be directly within the HTML output rather than a link to another JavaScript file. You can find out more about ionCube's HTML Obfusication script at: http://www.ioncube.com/html_encoder.php Hope that helps, P.S.: It's not just new developers who wish to encode their products (I'm talking about product source code, not HTML obfusication), for example PHPAudit, ClientExec, AWBS, WHMCS, WHMAP, ModernBill and other big products are all encoded.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read