Alternatives to HTML5 localStorage

折月煮酒 提交于 2020-05-27 06:15:26

问题


What are my alternatives to localStorage for persisting key/value pairs on the client? Ideally I'm looking for something that the user can't inadvertently delete (as they theoretically could with localStorage).


回答1:


With HTML5 your local storage options are limited to the following:

  • localStorage
  • cookies
  • Web SQL (in WebKit and Opera)
  • IndexedDB (in all modern decent browsers)

… however, users can delete data in any of these stores, and that is as it should be.




回答2:


An alternative could also be localForage, a js library that provides the ease of use of localStorage with all the advanced features of IndexedDB.

One of the benefits: you don’t have to convert your data structures to JSON in order to save them in the datastore.

Its API has support for ECMAScript 6 Promises, which provide a better way of handling asynchronous code. Unfortunately it doesn’t work well with any IE under 11.



来源:https://stackoverflow.com/questions/6909957/alternatives-to-html5-localstorage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!