我应该使用哪种 HTML5 离线存储解决方案来在我的 Web 应用程序中存储用户注释?
我正在编写一个 Chrome 应用程序,用户可以在其中创建和编写笔记(纯文本),我希望笔记能够离线保存。
我了解到html5有几种存储解决方案:localStorage
、Web SQL DB
、Application Cache
。我想知道您对如何选择它们的建议,考虑它们提供的尺寸、速度和使用的便利性。
I'm writing a Chrome app in which users can create and write notes(plain text), I'd like to the notes to be saved offline.
I've learned that there are several storage solutions from html5: localStorage
, Web SQL DB
, Application Cache
. I'd like to know your advice on how to choose from them, considering the size they offer, the speed, and the convenience of use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
localStorage
是迄今为止最简单的解决方案,您应该使用它来完成此任务。它允许你存储字符串,所以只要你的数据可以表示为字符串——它就可以工作(通常的做法是在保存之前将非字符串数据转换为 json,然后解析回来)。WebDB
是您的普通数据库。如果您需要跨多个表对数据运行复杂的查询,那么您可以使用它。对于存储笔记来说,这有点大材小用了。应用程序缓存
是完全不同的东西,我不知道如何在这里应用它。它用于缓存 html 页面和资源。localStorage
is by far the simplest solution and it's the one you should use for this task. It allows you to store strings, so as long as your data can be represented as strings - it will work (usual practice is to convert non-string data to json before saving, then parse is back).WebDB
is your normal database. If you need to run complicated queries on your data across multiple tables, then you can use it. For storing notes it would be an overkill.Application cache
is something completely different, I don't see how you can apply it here. It is for caching html pages and resources.本地存储
这基本上是一个键/值数据库,您可以使用它而不是 cookie 来存储设置或您可能在服务器上使用 memcache 等组件的其他用例。我个人会将其用于需要缓存的数据。
应用程序缓存
我假设您的意思是通过清单文件进行缓存。这应该是对缓存的其他用途的补充。这允许您缓存用户设备上的实际资源,例如图像、javascript 文件和 html 文件,以便它们在与互联网断开连接时可以在您的应用程序中工作
Web SQL DB
这是您要在其中存储用户数据的数据库,您可能也想将它用于存储在服务器上的 SQL 数据库中的数据。
Local Storage
This is basically a key/value database, you could use this instead of cookies to store settings or other usecases you might use components like memcache on the server for. I would personally use this for data that needs to be cached.
Application Cache
I assume you mean caching by the means of a manifest file. This should complement your other uses of caching. This allows you to cache actual resources on the users device, such as images, javascript files and html files so they can work in your application when they are disconnected from the internet
Web SQL DB
This is a database in which you want to store user data, you might want to use it for data you would store in a sql database on the server too.
根据此: https://developer.chrome.com/apps/offline_apps# saving-本地
IndexedDB 是推荐的存储机制。
According to this: https://developer.chrome.com/apps/offline_apps#saving-locally
IndexedDB is the recommended storage mechanism.