Html 如何同步 HTML5 本地/webStorage 和服务器端存储?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2631087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:42:45  来源:igfitidea点击:

How to synchronize HTML5 local/webStorage and server-side storage?

htmlweb-applicationsstorageoffline-modefirebase

提问by thSoft

Possible Duplicate:
Best way to synchronize local HTML5 DB (WebSQL Storage, SQLite) with a server (2 way sync)

可能的重复:
将本地 HTML5 数据库(WebSQL 存储、SQLite)与服务器同步的最佳方式(2 路同步)

I'm currently seeking solutions for transparently and automatically synchronizing and replicating across the client-side HTML5 localStorage or web storage and (maybe multiple) server-side storage(s) (the only requirement here that it should be simple and affordable to install on a regular hosting service).

我目前正在寻找透明和自动同步和复制跨客户端 HTML5 localStorage 或 Web 存储和(可能是多个)服务器端存储的解决方案(这里唯一的要求是它应该简单且易于安装)定期托管服务)。

So do you have any experience with such libraries/technologies that offer data storage which automate the client-server storage synchronization and allow data to be available either offline or online or both? I think this is a fairly common scenario of web applications supporting offline mode...

那么您是否有使用此类提供数据存储的库/技术的经验,这些库/技术可以自动执行客户端-服务器存储同步并允许数据离线或在线或两者兼而有之?我认为这是支持离线模式的 Web 应用程序的一个相当普遍的场景......

采纳答案by thSoft

Firebaseoffers this functionality as a service. Another alternative is Parse.

Firebase将此功能作为服务提供。另一种选择是Parse

回答by Nicholas Wilson

It kind of depends on what you want. There is a great tutorial to get you started at http://hacks.mozilla.org/2010/01/offline-web-applications/Unless you want to do something complicated, you should not need that much of a framework to do it for you. I guess you could save a few lines of code on the client using jQuery. You basically want to keep in your store a record of when the last change was made to the store, when the last update was to the server, and use send the localStorage variable encoded as JSON in an XHR (or just the bit of the local store you want to send). Then, on the server, you can decode the JSON and do what you want with it, processing it or just using PHP's serialize to dump it to a database.

这有点取决于你想要什么。在http://hacks.mozilla.org/2010/01/offline-web-applications/ 上有一个很棒的教程可以帮助您入门,除非您想做一些复杂的事情,否则您不需要那么多框架来完成它为你。我想您可以使用 jQuery 在客户端上保存几行代码。您基本上希望在您的商店中保留上次更改商店的时间、上次更新服务器的时间的记录,并使用在 XHR 中发送编码为 JSON 的 localStorage 变量(或只是本地的一部分)您要发送的商店)。然后,在服务器上,您可以解码 JSON 并使用它做您想做的事情,处理它或仅使用 PHP 的序列化将其转储到数据库。

If you have something particular in mind, do mention it.

如果你有什么特别的想法,一定要提到它。

回答by TinkerTank

this questionis rather similar.

这个问题比较相似。

There, 'quick connect' - http://quickconnect.pbworks.com/Using-Enterprise-Synchronizationand my personal favorit 'persistenceJS' - https://github.com/zefhemel/persistencejsare recommended.

在那里,推荐使用“快速连接” - http://quickconnect.pbworks.com/Using-Enterprise-Synchronization和我个人最喜欢的“persistenceJS” - https://github.com/zefhemel/persistencejs

As soon as I gather personal experience, I'll update this post.

一旦我收集到个人经验,我会更新这篇文章。

回答by thSoft

I just found a quite new framework which does just that: Impel.inTouch. Its schema definition seems a bit inconvenient, but definitely worth a try.

我刚刚找到了一个非常新的框架,它可以做到这一点:Impel.inTouch。它的模式定义似乎有点不方便,但绝对值得一试。