I agree on writing environment (client/server) agnostic code, but not in this way.
Js code should definitively run on the client and here is why:
- Instant feedback, no matter how bad is your connection: here if I click on something and there is no internet, I won't see a loading icon. You probably have to hack it.
- I'm not sure how it will scale and if it scales will be way more expensive than just using rest api (sockets are more expensive)
probably more problems.
I'm the creator of this game http://bitplanets.com which has a lot of shared code that runs both on the client and the server side. Some validation is done on the client (so you don't even hit the server if it fails + get instant feedback that your action is successfull or failed) and the same validation is done on the server side as well (so you can't hack it).
Examples:
- When you send a ship it will show a temporary ship immediately even if the server didn't receive yet the ship. If the client validates most likely it will be a valid ship (unless you hack it, but server side will deny your ship). Then when the server comes back saying that the ship is valid then the ship is not temporary anymore.
If you had a java backend everything would be so much more complicated. This is what I mean by having agnostic code, this validation function doesn't really care if is run on your client or on your server.
- Instant feedback, no matter how bad is your connection: here if I click on something and there is no internet, I won't see a loading icon. You probably have to hack it. - I'm not sure how it will scale and if it scales will be way more expensive than just using rest api (sockets are more expensive)
probably more problems.
I'm the creator of this game http://bitplanets.com which has a lot of shared code that runs both on the client and the server side. Some validation is done on the client (so you don't even hit the server if it fails + get instant feedback that your action is successfull or failed) and the same validation is done on the server side as well (so you can't hack it).
Examples:
- When you send a ship it will show a temporary ship immediately even if the server didn't receive yet the ship. If the client validates most likely it will be a valid ship (unless you hack it, but server side will deny your ship). Then when the server comes back saying that the ship is valid then the ship is not temporary anymore.
If you had a java backend everything would be so much more complicated. This is what I mean by having agnostic code, this validation function doesn't really care if is run on your client or on your server.