Reputation: 9301
How do game manufacturers prevent visitors from seeing the game code by right-clicking on the page in web browsers in popular HTML5/Canvas games? Are all the game code on the server and just a small part of the game code in the browser and then there is some kind of communication between server and browser with Ajax, Websockets or what?
I am curious and would like to know more about this? I'm learning game development in HTML5 with Canvas and I don't want to share all the code that I have spent so many hours to develop. How can I protect it?
Upvotes: 1
Views: 4723
Reputation: 542
There really isn't a way you can hide it per se.
However, minifying your code after completion makes it harder to decode (not to mention makes it run faster on many browsers). When whitespace is removed, code is all shoved into one line, variable names are reduced to single letters, and certain key things from the source are removed for optimization, it becomes increasingly difficult to figure out what the programmer is accomplishing with their code.
Upvotes: 1
Reputation: 69663
There isn't a way to hide your javascript from the end-user.
In order to execute it, it must be loaded by the users web browser. When it's on the users machine, the user can look at it.
You could use an obfuscator to make your code harder to read, but as long as it is readable for the browser, it is also readable for a determined human. Either live with it, or move your critical business secrets to server-sided code, and communicate with it through AJAX or web sockets.
Upvotes: 9