1

I have been developing a SPA with AngularJS and I have stored the user data in an Angular Value service but I do not feel confortable with that, basically because the Angular Value is not shared between browser tabs. So if the user opens a new browser tab and on every page refresh (F5) I have to request the server the user data like full name, email, etc. I am using a REST API.

Is this approach fine or not?. If I use localStorage it will help me to share data between tabs but I do not know if it is a better technique.

Ing.LkRuiZ
  • 262
  • 1
  • 3
  • 10

1 Answers1

3

There are only 3 places you could store your data in a browser

  1. Cookie
  2. Local storage
  3. Database (IndexedDB or Web SQL)

You can open your console panel to see these option.

Consideration:

  1. Security

It depends on how important or sensitive your data stored in the browser, if it is user sensitive, you should never stored them in the browser in the 1st place!

  1. Size

how big is the data, you going to store? if it is huge it is good to store them in the Database, you could check out some of this framework (PouchDB)

if it is small, you could just store them in the local storage

Community
  • 1
  • 1
Tim
  • 3,755
  • 3
  • 36
  • 57
  • Well based on what you said I have to decide with my team if the user data is sensitve, I guess not. I forgot to comment that part of the problem is that when I change the route using ngRoute I have to request again the user data, what about if I store the data in the $rootScope? and keep the requests when refresh and open new tabs. – Ing.LkRuiZ Jun 06 '15 at 16:20
  • then you need to a caching for every request made, u can check it here http://stackoverflow.com/questions/14117653/how-to-cache-an-http-get-service-in-angularjs – Tim Jun 07 '15 at 00:05
  • 1
    the user information can also be cached in a separate javascript file(added to header of layout page) that only changes if basic user information like name or thumbnail changes. and it can be cached on the client side so on every refresh it doesn't need to be downloaded, and on the server it's only generated on change of user info. the benefit is that it's faster than cookie or localstorage – Mohsen Shakiba Jun 07 '15 at 11:56