如何从服务器获取有关页面加载的信息
how to get info about page loading from server
我多次看到实时进度条指示从大数据 Web 应用程序加载的数据量,在页面开始呈现之前通知用户有关加载过程(% 或填充条)。如何实施?
我认为没有完美的解决方案。当然没有一个正确答案。这主要取决于 API/Server 的能力。我专注于如何获得前端的进展。在那里我看到了三种不同类型的数据传输。
❌ 计时器(最差的解决方案)
您可以使用基于平均加载时间的计时器。我不认为我必须解释为什么这不是一个好的解决方案。但这并不能真正给出正确的加载状态。
✔️ 投票中
您可以使用轮询系统来检索数据。当数据还没有准备好时,你 return 进度。如果数据准备好了,return数据。例如:
Step 1: GET the data from the REST-API
This call returns an id linked to the request. F.e. ID-1
Step 2: You poll each couple of (mili)seconds the status of the request, based on the ID.
This call returns for example:
{
status: 20,
data: []
}
As soon as the status is 100, the data is provided
✔️ Web 套接字 除了轮询之外,您还可以使用套接字使用正确的状态更新前端。服务器将向前端发布状态。对于这种方法,您还需要某种类型的 ID 以确保您只收到您的进度。
我多次看到实时进度条指示从大数据 Web 应用程序加载的数据量,在页面开始呈现之前通知用户有关加载过程(% 或填充条)。如何实施?
我认为没有完美的解决方案。当然没有一个正确答案。这主要取决于 API/Server 的能力。我专注于如何获得前端的进展。在那里我看到了三种不同类型的数据传输。
❌ 计时器(最差的解决方案) 您可以使用基于平均加载时间的计时器。我不认为我必须解释为什么这不是一个好的解决方案。但这并不能真正给出正确的加载状态。
✔️ 投票中 您可以使用轮询系统来检索数据。当数据还没有准备好时,你 return 进度。如果数据准备好了,return数据。例如:
Step 1: GET the data from the REST-API
This call returns an id linked to the request. F.e. ID-1
Step 2: You poll each couple of (mili)seconds the status of the request, based on the ID.
This call returns for example:
{
status: 20,
data: []
}
As soon as the status is 100, the data is provided
✔️ Web 套接字 除了轮询之外,您还可以使用套接字使用正确的状态更新前端。服务器将向前端发布状态。对于这种方法,您还需要某种类型的 ID 以确保您只收到您的进度。