HTML5 localStorage 的替代品
在客户端上保存键/值对时,除了 localStorage 之外,我还有哪些替代方案?理想情况下,我正在寻找用户无法无意中删除的内容(理论上他们可以使用 localStorage 删除)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 HTML5,您的本地存储选项仅限于以下内容:
……但是,用户可以删除任何这些存储中的数据,这是应该的。
With HTML5 your local storage options are limited to the following:
… however, users can delete data in any of these stores, and that is as it should be.
另一种选择是 localForage,这是一个 js 库,它提供了 localStorage 的易用性以及 IndexedDB 的所有高级功能。
好处之一:您不必将数据结构转换为 JSON 即可将它们保存在数据存储中。
它的 API 支持 ECMAScript 6 Promises,这提供了更好的处理异步代码的方法。
不幸的是,它不适用于 11 以下的任何 IE。
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.