过于依赖localStorage?
我正在构建一个演示,发现我在 localStorage 中存储大量数据,几乎不断地写入和读取值、解析和字符串化 JSON 等。
您发现自己非常依赖 localStorage 吗?
过度使用有什么危害? 定期将变量转换为 JSON 进行存储是否存在危险?
在我看来,如果我对大量此类数据进行数据库存储,我会显着增加数据库查询的数量和大小。
该演示非常以用户为中心,因此我存储诸如用户选择的项目和用户提供的输入之类的内容。本地存储的数据仅对用户有价值/感兴趣。
如果您正在构建类似带有预定结束日期和提醒的待办事项列表之类的内容,您会使用 localStorage 吗?为什么或为什么不呢?
我知道一个限制是用户只能在一台计算机上的一个浏览器上查看此内容,但这目前不是问题。
I'm building a demo, and find that I am storing lots of data in localStorage, almost constantly writing and reading values, parsing and stringifying JSON, etc. etc.
Do you find yourself relying on localStorage much?
What are the dangers of overusing it?
Are there dangers in regularly translating variables from and to JSON for storage?
It seems to me that if I did a db storage of lots of this data, I'd significantly increase the number and size of queries to my db.
The demo is very user focused, so I'm storing stuff like items the user has selected and input the user has provided. The data stored locally is only of value/interest to the user.
If you were building something like a todo list with scheduled end dates and reminders, would you use localStorage? Why or why not?
I know one limitation is that the user would only be able to view this content on one browser on one machine, but that isn't an issue for now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您实际上应该只将数据写入应该跨页面保存的本地存储。如果您不断地解析/字符串化 JSON,那么您的代码可能会比需要的慢得多。除了降低性能之外,本地存储中的可用空间也有限,因此您应该明智地使用它。
问问自己:“用户离开此页面后,有多少数据需要保留?”
You should really only write data to local storage that should persist across pages. If you're constantly parsing/stringifying JSON, then your code is likely much slower than it needs to be. Aside from reducing performance, there's a limited amount of space available in local storage, so you should use it judiciously.
Ask yourself: "How much of this data needs to stick around after the user leaves this page?"