提供 2 个 http 响应,第一个将显示加载,第二个将提供计算数据
我有一个应用程序需要很长时间来计算数据和数据。提供结果。理想情况下,我希望在请求页面后立即显示加载符号或类似的东西。一旦实际计算完成,我想显示结果。我的问题是如何解决这个问题,因为传统上 95% 的时间都花在准备响应上,因此在响应完全提供给用户之前不会看到加载图标,到那时显示加载图标将毫无意义,因为渲染响应不是问题点,而是“获取数据”部分非常耗时。
顺便说一句,我正在使用 java servlet + freemarker。
TL;DR 提供中间响应,直到准备好提供真正的响应。
I have an application that takes a long time to compute data & provide results. Ideally I would want to display a loading symbol or something similar, immediately once the page is requested & once the actual computation is completed I would want to display the results. My question is how to go about this because traditionally 95% of time is spent getting the response ready so the loading icon will not be seen untill the response is served completely to the user, by which time displaying the loading icon will be moot because rendering the response is not the problem point, it is the "getting the data" part which is very time consuming.
BTW, I am using java servlets + freemarker.
TL;DR Provide intermediate response until the real response is ready to be served.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阿贾克斯。这是它的最佳用例之一。您显示页面,对数据发出异步请求,显示加载屏幕,当请求返回时,您显示数据。
AJAX. That's one of its best use cases. You show the page, make an asynchronous request for the data, show the loading screen, and when the request comes back you show the data.