我正在编写的插件严重依赖于 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.
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/