Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter passing vs local storage

I have a lobby written in HTML5 / javascript. A .json file provides a few config parameters for the lobby and for the various other HTML5 games that can be launched from it. These parameters can either be passed to the games in the window.open string ( in the form of:

window.open(http://www.myLovelyDomain.com/index.html?username=bob&token=aaaXXX")

or could be held in localStorage and accessed by the game following it's launch.

My question is, what is the best (most secure/likely to cause least errors/etc) method? I know users can turn off localStorage, but I don't know how many do. Any thoughts?

like image 337
Simple Simon Avatar asked Nov 13 '12 09:11

Simple Simon


People also ask

Which is better localStorage or session storage?

For most cases, we use the local Storage object if we want some data to be on the browser. If we want it on the server, then we use it, and the session storage is used when we want to destroy the data whenever that specific tab gets closed or the season is closed by the user.

When should I use localStorage?

- Persistence: One of the most common reasons for using localStorage is to keep the data persistent. While sessionStorage can also store data in key-value pairs, it's cleared when the session ends. With localStorage, however, the data is continuous until it is explicitly removed.

What is the main difference between localStorage and sessionStorage?

The difference between sessionStorage and localStorage is that localStorage data does not expire, whereas sessionStorage data is cleared when the page session ends. A unique page session gets created once a document is loaded in a browser tab. Page sessions are valid for only one tab at a time.

What is the difference between local storage and session storage in angular?

The difference between localStorage and sessionStorage is that sessionStorage is lost the moment the browser is closed, while localStorage remain till the browser cache is cleared.


1 Answers

Advantages of localStorage over URL query strings

  • Less likely to be user edited
  • Less likely to be copy&pasted to someone else
  • Can persist across sessions
  • Wider choice of characters
  • (Marginally) less bandwidth usage (shorter GETs)
  • Can store whole files
  • Invisible to basic user

Disadvantages

  • Server doesn't get access to the variables without additional ajax
  • May be harder to debug
  • May need extra checks if things change every session (or consider sessionStorage)
  • Not supported by old browsers
  • Can't use cross-domain directly (may be advantage, depending on how you look at it)

For supported list and max sizes see here.

like image 84
Paul S. Avatar answered Sep 28 '22 10:09

Paul S.