Hi all:
We're developing a browser based social game, and it is a MMORPG game. We are using html/javascript/css as the frontend tech(comparing with flash). when the user loads our game for the first time, a bunch of files will be downloaded(external js/css) and several ajax call will be requested. The whole page won't be loaded again unless user refresh the page manually. And we create a js object to store the user-specific data, like cash, level and more. And it's subject to change during the user's coming operations. so we need to synchronize the data from the backend. A special issue is user's data can also be updated passively(by other users), this may happen in a fight by other users. so my question is how and when to synchronize?
Till now we underwent two stages, 1)whenever user clicks tabs(to show/hide a div in html) or possible operations(like fight/buy some thing), then we call the ajax request to get the fresh data from database each time. 2) similar with 1) but we just add a proxy to indicate whether the user's data is changed or not to reduce the useless database query. The ajax call will go to proxy at first.
for 1) we may have 70%+ useless ajax calls and db queries
for 2) we may have 70%+ useless ajax calls
Now we use 2)'s approach. But I don't think it's the best solution, since we still have 70%+ useless ajax calls. so is there any better solution to this use case?
explanations
useless ajax call: since the interval between 2 ajax calls, the user data may not change at all.