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

HTML5 games have viewable source code. Is there a way to make them like swf file?

How to hide the game algorithm?

What do you think of the Firefox JavaScript Deobfuscator Plugin and obfuscation?

share|improve this question
If you tell us the reason that you want to obfuscate, we can give you a much better answer, possible (probably), show you that you don't actually need to hide your code. – jcora Jul 16 '12 at 20:04
Also a SWF file isn't protected either.. you can easily decompile and extract all assets and code from it. There are obfuscators out there, but they aren't stopping something who's really determined. – bummzack Jul 16 '12 at 20:06
How much time you need to fully restore swf application after decompiling? – Rustam Jul 17 '12 at 7:41
Also, why would you want to? – brice Sep 13 '12 at 14:44

If you want to protect your source, don't write it in HTML/Javascript?

Part of the really nice things about the web as it's all human-readable. This makes it an excellent learning resource. If you're telling me that you've never looked at the source of a website to learn how it does something, then feel free to tell me I'm wrong.

I'm all bout sharing the love with code, otherwise I wouldn't answer questions on a website about offering help, all for free, would I?

Edit: I've said what I think of it, is there a way to make it non-readable? No, not in pure JS/HTML. The reason for this is simple: Somewhere down the line, it becomes readable. If you obfuscate it then a deobfuscator gets you. If you use a cipher or translate it somehow, at some point you have to translate it back into javascript (and the code to translate it back needs to be in your source too!).

The best you can do is to protect against bandwidth theft and obfuscate if you really feel the need, but it's not going to stop people if they're really determined.

share|improve this answer
flash and java can be decompiled, binaries can be disassembled, javascript can be deobfuscated. Your source is not protected just because you didn't write it in javascript. – Esailija Jul 16 '12 at 20:07
@Esailija the average effort it takes is not the same, except you are a trained reverse engineer/security expert/hacker/waht so ever. – daemonfire300 Jul 16 '12 at 21:59
Just a quote from anywhere: "What a man do any other man can undo." and I add to it: "With the right intent and will, nothing is really protected." – rcdmk Jul 17 '12 at 12:41
well i wouldnt call it a really nice thing; more of a "blessing and a curse" situation – CobaltHex Jul 17 '12 at 22:13
I would call it its 'base mechanic': it's really easy to steal on the web. This is why we have the speed and complexity of innovation we do. Newton, Picasso, Eliot and I'm sure more have all coined maxims around direct theft, even if nobly justified by the shoulders of giants. Shakespeare was excellent at theft. – Matt Kemp Jul 17 '12 at 22:21

You can put a lot of it on the server via Node.js and just return back results of functions. but other than that it's like Matt Kemp says. The code that runs is readable by a human, it's impossible to hide it.

share|improve this answer

Even if you don't obfuscate your code, HTML/ JS is already about the same level of difficulty to reverse engineer as SWF.

SWF files contain the original Actionscript code, (IIRC), with comments etc, unless they're obfuscated. Names of objects etc, are also contained within the SWF.

SWF decompilers / recompilers exist, and just because you can't see it with a text editor, does not mean SWF is in any way safe from reverse engineering.

In fact the level of obfuscation is really no different to a SWF. You could obfuscate your JS code using some obfuscator, but that just makes bug reports more difficult to interpret.

You probably want to focus your efforts into making something worth stealing, rather than preventing people stealing it. Plenty of SWFs get ripped off and used for unauthorised purposes (with changed graphics, etc)

share|improve this answer

No, and there is really no reason to! If you want to sell your work, you can do that without obfuscation. People pay for content, not code. Sell your artwork, story, music, etc., and give away the code freely (it already is, anyway).

share|improve this answer

Use the free Yahoo YUI compressor.

I use it because it compresses my code drastically (including removing comments and unnecessary whitespace). This lets me comment and structure my code exactly how I want without worrying about how easy I'm making it for thieves.

Additionally if you want to read the Javascript for a complex site after all variable and function names have been essentially destroyed -- well, good luck with that. It's much harder to figure out what code is doing when you have no hints.

(Though with YUI compressor you may need to augment its functionality to also get rid of function names. I have altered the way I name functions specifically for the purpose of automatically and selectively removing most function names. This may require some custom code on your end.)

share|improve this answer

HTML5 games have viewable source code. Is there a way to make them like swf files?

Yeah, use Flash and translate your code to ActionScript.

How would one go about hiding the game algorithms?

In absolute terms, you can't do that.

What do you think of the Firefox JavaScript Deobfuscator Plugin and obfuscation?

Obfuscation is nothing but a very thin barrier for somebody who'd be serious about stealing your code. Still, it's simple to setup, it can repulse the most dumb script kiddies, and it's the only thing you can do to protect client-side code. It has the additional benefit that it reduces the script size (faster download) and can even optimize the code (faster execution). Check this entry on Stack Overflow for details on obfuscation. Summary: you have plenty of options. I personally tried UglifyJS and had very satisfactory results.

share|improve this answer

As we all know HTML5 relies on JavaScript as a programming language. In theory all tools that protect JavaScript should work on HTML5.

The only tool I know that currently supports HTML5 in the context of Gaming development is JScrambler. I'm not sure if others will work.

For the porpoise of discussion, obfuscation is not a silver bullet. We have software that is compiled encrypted, protected with several anti copy solutions and still o can get them without paying. That said I believe that obfuscation beats leaving your code open for any one to read when you intention is not that.

I really love open source and support the movement yet sometimes closing the source makes lots of sense.

share|improve this answer

You can use native code. Programming on C++ and compile for HTML5. Cocos2d-X is a library that work on iOS, Android, and HTML5. Your code will be hidden.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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