问题描述
我是否需要传回任何 HTTP 标头以告诉浏览器我的服务器不会立即关闭连接并在收到 HTML 时显示?是否有必要让 HTML 像 flush() 那样增量显示?
Do I need to pass back any HTTP headers to tell the browser that my server won't be immediately closing the connection and to display as the HTML is received? Is there anything necessary to get the HTML to incrementally display like flush()?
这种技术曾经用于聊天之类的事情,但我正在考虑将其用于 COMET 类型的应用程序.
This technique used to be used for things like chat, but I'm thinking about using it for a COMET type application.
推荐答案
长轮询是一种常见的技术来做这样的事情;简单总结一下,它的工作原理如下:
Long polling is a common technique to do something like this; to briefly summarise, it works as follows:
客户端向服务器发送 XHR.
The client sends an XHR to the server.
- 如果有数据准备好,服务器会立即返回.
- 如果没有,服务器保持连接打开,直到数据可用,然后返回.
- 如果请求超时,请返回 1).
客户端上运行的页面接收到这些数据,并对其进行处理.
The page running on the client receives this data, and does what it does with it.
这就是 Facebook 实现其聊天功能的方式.
This is how Facebook implements its chat feature.
这篇文章也澄清了一些误解长轮询,并详细说明了这样做的一些好处.
This article also clears up some of the misconceptions of long-polling, and details some of the benefits of doing so.
这篇关于如何在很长一段时间内逐步向浏览器显示 HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)