We are developing a browser-based social game, and this is an MMORPG game. We use html / javascript / css as the frontend technology (compared to the flash). when the user loads our game for the first time, a group of files (external js / css) will be downloaded, and several ajax calls will be requested. The entire page will not be reloaded unless the user manually refreshes the page. And we create a js object to store user data such as cash, level, and more. And it can change during user work. so we need to synchronize the data with the backend. Special problem: user data can also be passively updated (by other users), this can happen in a battle with other users. so my question is: how and when to synchronize?
So far, we have gone through two stages: 1) whenever the user clicks the tabs (to show / hide the div in html) or possible operations (for example, fight / buy something), then we call the ajax request to get the latest data from the database every time. 2) similar to 1), but we just add a proxy to indicate whether user data has changed or not to reduce the useless database request. First, the ajax call will be sent to the proxy.
for 1) we can have 70% + useless ajax calls and db requests
for 2) we can have 70% + useless ajax calls
Now we use the 2) approach. But I do not think this is the best solution, since we still have 70% + useless ajax calls. so is there a better solution for this use case?
explanations
useless ajax call: with the interval between two ajax calls, user data may not change at all.
source
share