Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How do you prevent your JavaScript / HTML5 web game from being copied or altered?

If a game client is developed in Javascript, the source code can be found in browser. It's dangerous, because it's easy to hack the game, and patent can't be protected.

Are there any good ways to avoid this, e.g Javascript can be compiled to binary file then browser load and run the compiled javascript?

share|improve this question

marked as duplicate by Joe Wreschnig, bummzack, Josh Petrie, Noctrine Jul 12 '11 at 15:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Despite the fact this is an exact duplicate, it got voted up 3 times and there are 4 answers. I think that says something about the effectiveness of this site and it's users in helping people find previously asked questions. – Tim Holt Jul 12 '11 at 16:46
When I was asking the question, I had a look at the similar question list, but didn't find a "exact duplicate" one. If this boring you, you can provide a link to the "exact duplicate" one, instead of complain in comment. I' glad to remove the question. – Huang F. Lei Jul 13 '11 at 1:59
up vote 9 down vote accepted

The bottom line is there's no bullet-proof way to protect your HTML5/Javascript code. Obfuscation and minification will act as a deterrent. Closure Compiler is one such minifier.

If you really want to prevent people from cheating, store the state of the game on the server and turn the web page into a presentation/input layer that communicates with the server.

share|improve this answer
+1 for mentioning Closure Compiler – iamcreasy Jul 12 '11 at 16:03
+1 for " store the state of the game on the server" – dotNetSoldier Jan 26 '13 at 21:50

It's dangerous, because it's easy to hack the game, and patent can't be protected.

If a user hacks your game and cheats he ruins his own fun. The same can be done with desktop applications, it's just not as easy.

For the record flash applications are rather easy to decompile and hack aswell so most web platforms have this problem.

If a user can actively change public data by hacking with the client-side javascript then you have a vulnerability in your server. Any data which a user shouldn't be able to change should either live somewhere the user can't touch it (a server) or have a proper authentication portal in front of it so it can't be changed.

share|improve this answer

You can't stop people from reading your JavaScript, so consider that part of the game open-source. Design your game in such a way that seeing that code won't matter. Mostly this is done by only implementing the user interface, visuals, and sounds on the client-side; everything else in the game is done on your server and communicated between the client and server using AJAX techniques.

This exact same approach applies to Flash games as well, btw.

share|improve this answer

One of the first thing you can do to try to prevent people reusing your source code is to obfuscate it, meaning making it unreadable, thus very difficult to understand.

Then there's no javascript compiler, as it's interpreted in the browser (so you'd need to compile it to all existing browser).

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.