What should I do to protect my code?
Due to the open source code, a person can take the data, one by one. Alternatively, they save press ctrl+s. I want to protect it so that if someone wants to take my data, he has to connect to my site.
What should I do to protect my code?
Due to the open source code, a person can take the data, one by one. Alternatively, they save press ctrl+s. I want to protect it so that if someone wants to take my data, he has to connect to my site.
This is a classical caveat of serving client-side code. It is impossible to completely hide your code if you are going to send it to a client; he must receive a .js file in order to execute it in his browser, and that file is always viewable by some means.
You can attempt to obfuscate your code using a minifier like Uglify.js, but people can still prettify your code and examine it and attempt to figure out how it works.
Alternatively you could do everything server-side and serve images of the game to the user, but this would be impractical for any game with a moderately-high framerate.
Note that in most countries you have a copyright on whatever you write, so if someone was to ever steal your code you could sue them.
You can't protect your javascript functionality from copy-paste, as explained here.
To paraphrase the Borg..."obfuscation is futile"
(your code and your data must become visible for the browser to run it)
To slow thieves down:
If you're trying to protect your methods: minify your javascript.
If you're trying to protect your data: download data from server in real time (Ajax/websockets).