1

Use-case: I am currently working on a larger software, which consist of three different components. Every component has configurations, which I want to save in cookies, if the sessions is closed. If I reopening the website, the same configurations for every component should be restored.

Here is my question: Is it a good practice to save all configurations in one cookie or save the configurations for a component in an own cookie? All configurations are objects and consists of more then >10 properties.

Thanks for your help. :)

unos_mopsus
  • 123
  • 1
  • 8

2 Answers2

0

If you do not have access to an external API, you can save your configs in localStorage. Cookies are more server-side oriented, while localStorage is client-side.

  • "*Cookies are more server-side oriented, while localStorage is client-side.*" [Client-side cookies](https://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie) have existed since before local storage was available. – VLAZ Jul 20 '20 at 11:26
  • @VLAZ i think it was my bad, with the words i used to explain that. Sure they did exist, you are right there. – VladislavChudak Jul 20 '20 at 11:29
0

If the configurations are to be stored for the current browser only, I would store the complete object with JSON.encode(obj) in localStore:

Something like:

localStorage.setItem('objectName', JSON.stringify(myObject));

And to get the object:

var myObject = JSON.parse(localStorage.getItem('objectName'));
Maisen1886
  • 110
  • 1
  • 10