Question

I had a question on how localStorage works. I read the documentation and I was successfully able to implement it in our web game. We are using ImpactJS engine and using this plugin -> https://github.com/jsantell/ImpactStorage for the our purposes. Though I am still very much new to the whole concept of persistent data on web

In our game we expect around 1000 or more teams ( each team would have around 5 players ) playing the game on different browsers, different machines.

Now all the teams have their information stored on the database which creates a unique id for each of them. And for each team there would be around 40 localStorage key values that I am using for different gameplay elements

Before getting in any kind of trouble in future, I want to make sure that my whatever values I use for localStorage would persist throughout and work on different systems, different browsers meaning If the value of one of the keys in localStorage is updated, would the keys be updated on other different systems too for that same team?

For now I tested it in one machine and 3 different browsers and the values get updated everywhere but would it also work on different machines?

If someone could briefly explain in simple terms how exactly localStorage works in such scenario?

Thanks!

Était-ce utile?

La solution

You can think of localStorage as cookies on steroids. If you've used cookies, you are not new to persistent data on the web. You get persistent browser-based (and browser-limited) string-based key value storage, more storage* and you lose the straight-forward ability for cross-subdomain storage (you can accomplish that goal in this manner). It will not sync with your server automatically, it will not even sync with other browsers on the same machine without some external process. The localStorage programming concepts will (mostly*) work the same on any browser that supports the W3C localStorage spec

I tested it in one machine and 3 different browsers

3 different browsers as in Chrome, Firefox and IE or 3 different tabs/windows of the same browser? I ask because localStorage does not synchronize between browsers (unless you have some external process performing the synchronization).

Hope this helps

* different browsers have different levels of storage they allow, this answer explains more

Autres conseils

localStorage is specific to the individual browser of the individual user on their individual computer or device - so is not suitable for sharing data between different browsers, devices or team members. It is also worth noting that users can delete their localstorage for a site at any time, and privacy concious users may do this frequently in the process of clearing their history and private data. You will want to look at a server side database solution such as SQL server or MySQL based on the question.

You could however use localStorage to persist/cache key/value pairs locally to avoid round-trip lookups or allow use offline.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top