javascript - localStorage 的持久性如何?

标签 javascript persistence local-storage persistent-storage

我正在编写的插件严重依赖于 localStorage。所有用户设置都存储在其中。有些设置要求用户编写正则表达式,如果他们的正则表达式规则在某个时候消失了,他们会很伤心。 所以现在我想知道 localStorage 的持久性如何。

来自 the specs :

User agents should expire data from the local storage areas only for security reasons or when requested to do so by the user.

上面的内容看起来就像客户端的 cookie 一样工作。 IE。当用户清除所有浏览器数据(历史记录、cookie、缓存等)时,localStorage 也将被 chop 。这个假设是否正确?

最佳答案

Mozilla 像 cookie 一样实现它:

DOM Storage can be cleared via "Tools -> Clear Recent History -> Cookies" when Time range is "Everything" (via nsICookieManager::removeAll)

https://developer.mozilla.org/en/DOM/Storage

In DOM Storage it is not possible to specify an expiration period for any of your data. All expiration rules are left up to the user. In the case of Mozilla, most of those rules are inherited from the Cookie-related expiration rules. Because of this you can probably expect most of your DOM Storage data to last at least for a meaningful amount of time.

http://ejohn.org/blog/dom-storage/

Chrome 像缓存一样实现它:

LocalStorage is Not Secure Storage

HTML5 local storage saves data unencrypted in string form in the regular browser cache.

Persistence

On disk until deleted by user (delete cache) or by the app

https://developers.google.com/web-toolkit/doc/latest/DevGuideHtml5Storage


至于“Cookie 的替代品”,not entirely

Cookies and local storage really serve difference purposes. Cookies are primarily for reading server-side, LocalStorage can only be read client-side. So the question is, in your app, who needs this data — the client or the server?

关于javascript - localStorage 的持久性如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16577475/

相关文章:

javascript - 如何在 Service Worker 中持久化数据

javascript - Firefox 中的 localStorage 不可靠

google-chrome - 如何处理从 Chrome 80 开始的新的第三方 cookie 规则?

javascript - 正则表达式:在起始定界符和可选的结束定界符之间捕获

java - JPQL:解析查询时出现语法错误,意外标记

java - JPA merge() 仅更新部分字段。其他变化不被认可

sql - PostgreSQL 列类型从 bigint 到 bigserial 的转换

javascript - 如何使用 jQuery 制作可编辑的 UL LI 列表?

javascript - 在 d3.js 中的每个 X 轴日期标签下方添加自定义文本

javascript - 需要帮助使字符串输入返回一个统计字母对频率的直方图