2

One benefit of single page applications like Angular.js, is that you can store data in a global variable and access in multiple routes.

With multiple page applications, the data is lost during navigation. Ideally, such data should remain available on the user side while the user session is active. Using SessionStore does not solve this issue. There is the possibility of using LocalStore, but it is not limited to the session. One could fiddle something by extracting the session id from cookies.

Is there a better solution than using LocalStore?

  • What is wrong with `sessionStorage`? It will not save state during navigation as long as the browser isn't closed/ – Jordan Davis Jul 07 '15 at 20:02
  • Do you mean that if I save something in sessionStorage, it will remain available as long as the browser is opened? The doc seems to say that it is erased when a new tab is created... Or is there something I am missing? Thanks! – Jérôme Verstrynge Jul 07 '15 at 20:07
  • 1
    If you open a new tab, it will start a new session for that tab, but your initial tab will still have it's data. This makes sense, because if you are saving application state, you will want that data to be different across multiple tabs. – Jordan Davis Jul 07 '15 at 20:49
  • Ok, thanks for the feedback; I'll perform some tests. – Jérôme Verstrynge Jul 08 '15 at 06:46

1 Answers1

1

That's not an advantage. Global State is Evil.

Let's review over the things you've said:

  • Using SessionStore does not solve this issue - What? Why? It sounds exactly like you want. The browser knows what a "session" is a lot better than the server. It sounds to me that it's exactly what you want.
  • There is the possibility of using LocalStore, but it is not limited to the session. - That is true. localStorage sticks to the end of time, until you (or the user) delete it.
  • One could fiddle something by extracting the session id from cookies. - No, that's not true. localStorage and sessionStorage can only be accessed by scripts run on the same domain (same as cookies), except localStorage/sessionStorage are never sent to the server (unless explicitly done so with an AJAX request or similar techniques). If anything, one would manipulate cookies to steal the session ID.
Madara's Ghost
  • 8,787
  • 9
  • 25
  • 33