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?

asked Jul 6, 2015 at 19:38
4
  • What is wrong with sessionStorage? It will not save state during navigation as long as the browser isn't closed/ Commented Jul 7, 2015 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! Commented Jul 7, 2015 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. Commented Jul 7, 2015 at 20:49
  • Ok, thanks for the feedback; I'll perform some tests. Commented Jul 8, 2015 at 6:46

1 Answer 1

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.
answered Sep 7, 2015 at 10:54
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.