使Web应用程序脱机的策略?

时间:2023-01-19 22:11:35

We're currently building a web app (Django, Ember), and we just found that most of our potential customers require sporadic offline access to the application.

我们目前正在构建一个Web应用程序(Django,Ember),我们发现大多数潜在客户都需要对应用程序进行零星的离线访问。

What we need is not just "presenting" the app so user can navigate, caching stuff in the Manifest and so on (which I guess we will need eventually too), but we must let users actually operate as much as possible as if they were online. There will be obviously some features unavailable, but basic usage of the app should be available.

我们需要的不仅仅是“呈现”应用程序,以便用户可以导航,缓存清单中的内容等等(我想我们最终也需要),但是我们必须让用户尽可能多地操作,就好像它们是线上。显然有一些功能不可用,但应该可以使用应用程序的基本用法。

That said, I'd love to hear some thoughts on people that have confronted this scenario before. The way I see this, we need to:

也就是说,我希望听到一些关于以前遇到这种情况的人的想法。我看到这个的方式,我们需要:

1.- Either check if we're online / offline constantly or let the user specify when they're going offline (sort like Airplane mode in a smartphone).

1.-检查我们是否经常在线/离线,或让用户指定他们何时离线(如智能手机中的飞行模式)。

2.- All data should be dumped into IndexedDB and from that moment on we use IndexedDB for anything related with data.

2.-所有数据都应该转储到IndexedDB中,从那时起我们就使用IndexedDB来处理与数据相关的任何事情。

3.- When the user goes back online, a Synch process must try to dump the data from the offline user to the db online. While this might look dangerous, I don't expect a lot of users going offline at the same time while other online users are using the app, so I expect this synch process to don't become a real nightmare, also I don't expect to have race conditions.

3.-当用户重新联机时,Synch进程必须尝试将数据从脱机用户转储到db online。虽然这可能看起来很危险,但我不希望很多用户同时离线,而其他在线用户正在使用该应用程序,所以我希望这个同步过程不会成为真正的噩梦,我也不会期待有竞争条件。

Well, and there is obviously the option to create a Desktop standalone app...but I will try to avoid this as much as possible...

好吧,显然有创建桌面独立应用程序的选项......但我会尽量避免这种情况......

Thanks!

1 个解决方案

#1


3  

  1. To check if the user is offline or online , you can use navigator.onLine but this property is not supported on all browsers. Then, if you target some of this browsers, you will have to implement an other solution with AJAX calls for example.

    要检查用户是离线还是在线,您可以使用navigator.onLine,但并非所有浏览器都支持此属性。然后,如果您针对某些浏览器,则必须使用AJAX调用实现其他解决方案。

  2. Concerning the synchronisation, you can use available solution like CouchDB (NoSQL) on your server and use PouchDB (indexedDB) in your javascript front-end that will ease you the synchronisation process. If it doesn't meet your expectations, implement your own solution, to synchronize an indexedDB with your server database (MySQL, Postgres, MongoDB, etc...), of course, you can still use pouchDB on the front-end.

    关于同步,您可以在服务器上使用CouchDB(NoSQL)等可用解决方案,并在javascript前端使用PouchDB(indexedDB),这将简化同步过程。如果它不符合您的期望,请实现您自己的解决方案,将indexedDB与您的服务器数据库(MySQL,Postgres,MongoDB等)同步,当然,您仍然可以在前端使用pouchDB。

  3. Regarding performance, I think it will depend greatly on:

    关于性能,我认为它将在很大程度上取决于:

    • the number of servers that host your web applications
    • 托管Web应用程序的服务器数量

    • the number of replica of your master database
    • master数据库的副本数量

    • configuration of your servers (CPU and RAM)
    • 服务器配置(CPU和RAM)

#1


3  

  1. To check if the user is offline or online , you can use navigator.onLine but this property is not supported on all browsers. Then, if you target some of this browsers, you will have to implement an other solution with AJAX calls for example.

    要检查用户是离线还是在线,您可以使用navigator.onLine,但并非所有浏览器都支持此属性。然后,如果您针对某些浏览器,则必须使用AJAX调用实现其他解决方案。

  2. Concerning the synchronisation, you can use available solution like CouchDB (NoSQL) on your server and use PouchDB (indexedDB) in your javascript front-end that will ease you the synchronisation process. If it doesn't meet your expectations, implement your own solution, to synchronize an indexedDB with your server database (MySQL, Postgres, MongoDB, etc...), of course, you can still use pouchDB on the front-end.

    关于同步,您可以在服务器上使用CouchDB(NoSQL)等可用解决方案,并在javascript前端使用PouchDB(indexedDB),这将简化同步过程。如果它不符合您的期望,请实现您自己的解决方案,将indexedDB与您的服务器数据库(MySQL,Postgres,MongoDB等)同步,当然,您仍然可以在前端使用pouchDB。

  3. Regarding performance, I think it will depend greatly on:

    关于性能,我认为它将在很大程度上取决于:

    • the number of servers that host your web applications
    • 托管Web应用程序的服务器数量

    • the number of replica of your master database
    • master数据库的副本数量

    • configuration of your servers (CPU and RAM)
    • 服务器配置(CPU和RAM)