JavaScript jQuery – Using SessionStorage to Keep Client Side State

client-serverjavascriptjquery

I am working on an web app and I would like to keep the client data in the LOCAL
session storage.

I can't use the servers session and the app will only call some existing rest WS.I have to develop pure client side app, no server side rendering

In this case when going from one page to another I plan to read the data previously stored
for each page from local session storage and render each page accordingly so refreshing the page will not affect the behavior by deleting client data for each page

I am sure is doable but is this a proper way keeping each page's data?

This is suitable for me because for years I have done frontend development with in Java Swing.

Thanks

Best Answer

Although using server side session state to store user data between page loads works, the downside is it eats memory on the server per user. So its not scalable.

keeping data in a cookie, although it seems old fashioned and you have to worry about its security. Is generally considered better.

A more modern approach is to use javascript client side databases. Or in a single page app you can simply persist the data in memory client side.

You can also get around the memory problem by storing the session in a DB or a separate scalable cache, such as memcache or aerospike etc However, this starts to raise more fundamental questions about the architecture of your application. Why do you need to have this state stored? is it actually better than regenerating it from a database on each page load? etc etc

Again in general I would say the popular view is to move towards stateless JSON services which are called via client side AJAX. (I'm not going to call it "REST" becuase its such a loaded term)