HTML5 localStorage 长期安全吗?
我正在学习 HTML、Javascript 等,并决定在 Chrome Web Store 上制作一个小型 Web 应用程序作为教育项目。该应用程序在 localStorage 中存储了一些重要数据(本质上是保存的小型文本文件),我想知道这种实现选择是否太脆弱。我知道如果用户的硬盘坏了或手动删除它,用户就会丢失数据,但是在正常情况下数据是否有危险?例如,Chrome 是否出于维护原因决定清理 localStorage?
谢谢, 亚历克斯
I am learning HTML, Javascript, etc., and decided to make a small web app on the Chrome Web Store as an educational project. The app stores a few bits of important data in localStorage (essentially small saved text files), and I was wondering if this implementation choice is too fragile. I know that the user will lose data if their hard drive dies or they manually delete it, but is the data in danger under normal circumstances? For example, does Chrome ever decide to clean out localStorage for maintenance reasons?
Thanks,
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,当您选择“清除浏览数据”时,Chrome 会删除所有内容(包括本地存储),如果某些用户被告知执行“清空浏览器缓存”之类的操作,但没有意识到其含义,他们可能会这样做。
HTML5 规范没有指定任何有关数据安全的内容,可能是因为它是一个非常年轻的草案。为了安全起见,我会将这些数据存储在云中 - 这是您的用户所期望的。
By default, Chrome deletes everything - including local storage - when you select "Clear Browsing Data", which some users might do if they're told to do something like "empty your browser's cache" without realising the implications.
The HTML5 spec doesn't specify anything with regards to the safety of data, possibly because it's a very young draft. I'd play it on the safe side and store that data in the cloud as well - it's what your users expect.
我建议像对待 cookie 一样对待本地和会话存储。如果它存在但并不重要,那么很有帮助,并且您可以在没有它的情况下继续操作(并且可能重新创建它并再次存储它)。
I'd suggest treating local and session storage as you would cookies. Helpful if it's there but not vital, and you can carry on without it (and possibly recreate it and store it again).