Obfuscate javascript code

Hi,
I started writing games via cocos2djs - it’s really great. The apps also need to be available via web.

So I published some first test versions, but couldn’t find a way to effectly obfuscate my code.
The official tutorial seems to be out-of-date. The mentioned “obfuscate.py” file does not exist in current versions.

I tested the online Closure Compiler Service, but it only works in simple mode. As far as I understood, the advanced mode needs to be configurated, so it knows what to exlude and so on.

Would be really great if some dev could describe how to get advanced obfuscating working. Many thanks in advance…

1 Like

Hi, @pete01

I’m happy that you like Cocos2d-JS, here is our latest document root: http://www.cocos2d-x.org/docs/manual/framework/html5/en

For obfuscating your javascript code to publish on web, you can simply use our cocos console tool. It can obfuscate all the engine code (only the modules you need) and your game code to a single js file using closure compiler. The command is:

cocos compile -p web -m release --advanced

advanced means closure compiler’s advanced mode, if no advanced specified, it will be compressed under simple mode.

Here is a complete document about the workflow: http://www.cocos2d-x.org/docs/manual/framework/cocos2d-js/2-working-environment-and-workflow/2-2-cross-native-browser-game-with-cocos-console/en

1 Like

Hi pandamicro,
thanks so much for your fast reply :thumbsup:

I just tested it and both simple and advanced mode worked perfectly. Very easy to use!
Also thanks for the updated document/manual link. Looks like there’s some interesting stuff for me.
Somehow I missed it before…

Does the cocos code IDE automatically compress and obfuscate the JS files using the google closure compiler when compiling?

Many suggest the usage of cocos compile -p android -m release from command line, I need to know if i could get the exact same result when running it from cocos code IDE v1.2.0? is it enabled by default? what is the type of obfuscation used?

Hi,
I didn’t get any way to obfuscate your cocos2d-JS file. If anyone have some approach then reply me asap.