HTML5 离线数据存储选项
我的一位开发人员朋友最近刚刚在一家新公司开始工作,他的任务之一是开发一个新的 Web 应用程序,允许用户在员工在远程位置现场时离线工作,然后与服务器端同步他们还没有确定服务器端提供商的数据库(我猜会是 SQL Server)。
我环顾四周,似乎有两个可行的选择:LocalStorage 和 IndexedDb,其中 LocalStorage 是更流行的技术?他们想要使用 HTML5,这一切都很好,但长话短说,我的问题是……
- 他们在 HTML5 中的离线数据存储选项是什么?
- 是否有提供更好支持的旧解决方案?
- 这些方法风险较小吗?
- 实施时间更少?
在 Web 应用程序中离线存储数据的概念似乎并不是一个新想法,但在当今最新的技术(html5、asp.net 4.0/4.5)中这样做是您开始进入稀疏探索领域的地方。
- 您的公司所做的哪些事情是有效的,哪些是无效的?
任何基于智能证据的回复都很可能会得到我的支持,所以不要急于得到第一个答案并尝试快速得分,我在这里寻找一些良好的可靠反馈。谢谢。
A developer buddy of mine just recently started at a new company and one of his tasks is to come up with a new web application that allows their users to work offline when their staff are onsite in remote locations and then later to sync with a server side database of which they have not yet determined a server side provider yet (i'm guessing it will be SQL Server).
I've done some looking around and it seems like two viable options are LocalStorage and IndexedDb, with LocalStorage being the more popular technology? They want to go HTML5 and that's all fine and dandy, but long story short my question(s) is/are...
- What are their offline data storage options in HTML5?
- Are there older solutions that have better support?
- are those methods less risky?
- less time to implement?
The concept of storing data offline in a web application doesn't seem like a new idea, but doing so in today's newest technologies (html5, asp.net 4.0/4.5) is where you start getting into sparsely explored territory.
- what are some things that maybe your company does that works, and what doesn't work?
Any intelligent evidence based replies will more than likely get my upvote so don't just rush to get the first answer and try to score some quick points, I'm looking for some good solid feedback here. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML5中的离线存储有几种可能性:
网络存储
Web SQL 数据库
索引数据库
文件系统 API
您在这里对所有这些选项都有很好的介绍:
http://www.html5rocks.com/en/tutorials/offline/whats-offline/#toc-older-storage
与旧选项(Cookie、基于插件的存储、浏览器特定的功能),我将引用文章中的内容:
“较新的存储 API,我们可以称之为“HTML5 存储”,在开放性和标准合规性方面通常更为优越。当然,并非所有浏览器都包含所有新的 API,并且您可能必须支持根本不包含任何新 API 的旧浏览器,因此旧技术对于优雅降级仍然有用。”
其他有用的链接:
http://php-html.net/tutorials/html5- local-storage-guide/
http://www.tutorialspoint.com/html5/html5_web_sql.htm
希望这有帮助...
There are several possibilities of offline storage in HTML5:
Web Storage
Web SQL Database
IndexedDB
Filesystem API
You have a very good presentation of all these options here:
http://www.html5rocks.com/en/tutorials/offline/whats-offline/#toc-older-storage
Compared to older options (Cookies, Plugin Based Storage, Browser-specific features) , I'll quote from the article:
"The newer storage APIs, what we might call "HTML5 storage", are generally superior in terms of openness and standards compliance. Of course, not all browsers include all of the new APIs, and you may have to support older browsers that don't include any of them at all. So the older techniques are still useful for graceful degradation."
Other useful links:
http://php-html.net/tutorials/html5-local-storage-guide/
http://www.tutorialspoint.com/html5/html5_web_sql.htm
Hope this helps...
我认为您最好的选择是使用本地存储,因为它是 HTML5 下可用的存储选项中实施最广泛的标准。
IndexedDB 已经被过度设计(在我看来),而且由于 Mozilla 坚持 比切片面包更好,WebSQL 的未来看起来和 Mozilla 一样有点不确定拒绝实施它,由于双方之间的僵局,它不再进行 W3C 和实际实现它的浏览器供应商(Chrome/Safari/Opera)。
由于智能手机的采用,目前浏览器出现了爆炸式增长,因此很难确定有多少市场支持 HTML5 LocalStorage 功能,但使用 statcounter 我已经能够在 Chrome (4+)、Firefox (3.+)、Safari 之间进行计算(4+)、Opera (10.5+) 和 IE (8+),包括 iPhone 和 Android 设备,您将占据大约 80-85% 的市场份额,并且这个数字每月以 1-2% 的速度增长。其余的是 IE 6/7(它顽固地倾向于坚持下去)、新浏览器的旧版本(通常具有使它们保持最新状态的更新功能)以及一些停留在石器时代的移动浏览器。
至于旧选项,我会添加用户数据持久性 对于 IE6/7 到 @user998692 提供的列表,但无论哪种方式,你都会遇到很多浏览器不兼容问题和对大杂烩的支持技术,这将使您的代码库和测试变得复杂,并相应地增加您的交付时间(和成本)。但是,如果您确实想走这条路,我建议您看看 PersistJS 作为将其组合在一起的人已经完成了您需要做的大部分工作。
如今,它更值得期待(当您的应用程序传播并获得广泛的用户群时,1-2 年后市场会是什么样子)而不是向后看,所以我认为 HTML5 LocalStorage 可能是您的最佳选择。
I think your best choice is using Local Storage since its the most widely implemented standard of the storage options available under HTML5.
IndexedDB has been over-engineered (in my opinion) and is not widely supported (yet) for all of Mozilla's insistence that its better than sliced bread, and WebSQL's future is looking a bit uncertain as Mozilla is refusing to implement it and it is no longer being worked on due to an impasse between W3C and the browser vendors who have actually implemented it (Chrome/Safari/Opera).
There is currently a bit of a browser explosion happening thanks to smartphone adoption, so its hard to determine how much of the market supports HTML5 LocalStorage features but using statcounter I've been able to calculate that between Chrome (4+), Firefox (3.+), Safari (4+), Opera (10.5+) and IE (8+), including iPhone and Android devices you'll have captured around 80-85% of the market, with this figure going upwards a rate of 1-2% per month. The remainder being IE 6/7 (which stubbornly tends to hang on), older versions of new browsers (with update features that generally kept them current), and some mobile browsers stuck back in the stone age.
As for older options, I would add User Data Persistence for IE6/7 to the list provided by @user998692 but either way you're going to be caught up with lots of browser incompatiblity issues and support for a hodge-podge of technologies, which will complicate your codebase and testing and increase your delivery timelines (and cost) accordingly. If you do want to go down this road, however, I would recommend you take a look at PersistJS as the guys who put it together have done much of the work you would need to already.
These days its worth more looking forward (to what the market will look like in 1-2 years time when your app is propagating and gaining a wide user base) than backwards, so I'd say HTML5 LocalStorage is probably your best option.