HTML5 - Web sql 设置离线存储
如何在 Web SQL 中设置离线存储模式(离线/在线)的基本切换?我知道有 javascript
window.navigator.onLine
。我可以检查模式,然后完成一个过程...
//All GET/POST performed with AJAX
//On Startup pulldown entire accessible database into offline storage (Doesn't seem secure IMO)
//if(read) pull from offline
//if(create, update, delete and online) pull from standard db, mark changes with offline expiration flag
//if(create, update, delete and offline) perform operation on offline storage, persist with POST when next online (change flag)
我问这些标准任务是否有任何 OOB 集成?
How do I setup the basic switching of offline storage modes (offline/online) in Web SQL? I know there's javascript
window.navigator.onLine
. I can check the mode and then go through a process...
//All GET/POST performed with AJAX
//On Startup pulldown entire accessible database into offline storage (Doesn't seem secure IMO)
//if(read) pull from offline
//if(create, update, delete and online) pull from standard db, mark changes with offline expiration flag
//if(create, update, delete and offline) perform operation on offline storage, persist with POST when next online (change flag)
I'm asking if there is any OOB integration for these standard tasks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
navigator.online
属性通常不是很有用 - 在桌面浏览器中,它所做的只是挂钩到文件 -> 。离线工作菜单。它可能在 iPad 上更有用,我不知道,因为我没有 iPad,而且我猜没有“文件”菜单,但我建议您测试一下。解决此问题的常见方法是在清单的后备部分中设置两个易于区分的文件。每次您想要连接回服务器时,都会尝试使用 AJAX 获取文件,并在回调中检查它以查看是否获得了在线文件或后备文件,然后进行相应的分支。
The
navigator.online
property generally isn't very useful - in a desktop browser all it does is hook into the File -> Work Offline menu. It may be more useful on an iPad, I don't know because I don't have one, and I'm guessing there's not a File menu, but I would recommend you test.A common approach to this issue is to set up two easily distinguishable files in the fallback section of your manifest. Every time you want to connect back to the server attempt to fetch the file with AJAX and, in the callback, check it to see if you got the online file or the fallback, then branch accordingly.
您不应该使用 Web SQL,因为该规范在几个月前就被取消了。您应该使用本地存储。除非你专门为 iphone 之类的东西编码,但即使这样你也不知道 webkit 中的规范会持续多久。
You shouldn't be using Web SQL as that spec was nixed a new months ago. You should be using Localstorage. Unless you are specifically coding for something like the iphone, but even then you dont know how long the spec will be in webkit.