Best way to store small UI user preferences in web app?

后端 未结 4 829
执念已碎
执念已碎 2020-12-02 18:42

I have a web app I\'m developing and quite like the idea that if the user makes changes to the view of the UI (eg. Lists open or closed, certain viewing preferences) those c

4条回答
  •  臣服心动
    2020-12-02 19:00

    Using HTML5 local storage is really easy:

    localStorage.setItem('someName', 'savedData');
    

    When you have to retrieve it later you just use:

    var data = localStorage.getItem('someName');
    

    Using HTML5 has some drawback too, I suggest you to definitely add support to older browsers via cookie etc. Then again if you wish to enable the user to have the same settings regardless of the location he logs in from, you have no other option than to use a database table.

    Extra note: Beware that cookies are sent with each request to the server. If low bandwidth is important and there are numerous settings that are defined in a cookie, using a database table or local storage makes more sense.

提交回复
热议问题