如何使我的WebApp脱机使用?

时间:2021-09-29 16:56:50

If you are using Google Calendar, you may noticed that they have "Offline" feature. You can use Google Calendar even if you are offline. I am interested to know what is the strategy that they are using to enable this feature?

如果您使用的是Google日历,则可能会发现他们具有“离线”功能。即使您处于离线状态,也可以使用Google日历。我很想知道他们用来启用此功能的策略是什么?

I have a PHP/MySql invoicing application, and I want to allow users to use my system even if they are offline, then when internet is back, data should be synced with the online version.

我有一个PHP / MySql开发票应用程序,我想允许用户使用我的系统,即使他们离线,然后当互联网回来时,数据应该与在线版本同步。

I don't want to install my codes in my client's PCs, so I hope if someone has an idea that allows me to do same as what they did in Google Calendar or any other idea that may help.

我不想在客户端的PC上安装我的代码,所以我希望如果有人有一个想法可以让我做他们在谷歌日历中所做的相同或任何其他可能有用的想法。

1 个解决方案

#1


1  

There is a Javascript variable called localStorage. You can store there a queue of commands to the executed and you can can implement a synchronize function, like this:

有一个名为localStorage的Javascript变量。你可以在那里存储一个命令队列,你可以实现一个同步函数,如下所示:

function synchronize(queue) {
    while (!queue.isEmpty()) {
        queue.pop().execute();
    }
}

You can use anything else, including Offline Storage, but remember that Offline Storage is supported only by HTML5, so if you want to support older browsers, then you need to have a fallback logic for those as well.

您可以使用其他任何东西,包括离线存储,但请记住,只有HTML5支持离线存储,因此如果您想支持旧版浏览器,那么您还需要具备回退逻辑。

#1


1  

There is a Javascript variable called localStorage. You can store there a queue of commands to the executed and you can can implement a synchronize function, like this:

有一个名为localStorage的Javascript变量。你可以在那里存储一个命令队列,你可以实现一个同步函数,如下所示:

function synchronize(queue) {
    while (!queue.isEmpty()) {
        queue.pop().execute();
    }
}

You can use anything else, including Offline Storage, but remember that Offline Storage is supported only by HTML5, so if you want to support older browsers, then you need to have a fallback logic for those as well.

您可以使用其他任何东西,包括离线存储,但请记住,只有HTML5支持离线存储,因此如果您想支持旧版浏览器,那么您还需要具备回退逻辑。