html5 sse 在chrome、firefox上的不同表现
2017-03-28 14:22
204 查看
虽然两者都实现了html5 sse,但是两者处理方式是不同的。
若在服务器端处理的时候。若没有返回数据,在FF下会中断SSE连接,并且都不会在连接上了。
因此必须每次连接都有返回数据才行。而在CHROME下则可以处理这种情况。没有返回也可以再次发起连接。
Fireforx上sse是每5秒发起一次连接。而chrome是3秒。
Chrome:
Sat Oct 12 2013 16:36:06 GMT+0800 (中国标准时间) article.js:2067 http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed article.js:2075
Sat Oct 12 2013 16:36:09 GMT+0800 (中国标准时间) article.js:2067 http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed article.js:2075
Sat Oct 12 2013 16:36:12 GMT+0800 (中国标准时间) article.js:2067 http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed article.js:2075
Sat Oct 12 2013 16:36:16 GMT+0800 (中国标准时间) article.js:2067 http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed
Firefox:
Date {Sat Oct 12 2013 16:36:29 GMT+0800}
article.js (line 2067) http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed
article.js (line 2075)
Date {Sat Oct 12 2013 16:36:34 GMT+0800}
article.js (line 2067) http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed
article.js (line 2075)
Date {Sat Oct 12 2013 16:36:39 GMT+0800}
article.js (line 2067) http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed
SSE的缺点是,定制性不高,API的参数很少,比如不能自定义轮询的时间间隔。
它本质上就是轮询get 类型的AJAX。
在特定的需求下会比较有用,比如做个时间显示。如果用JS写,不能保证时间一致,用服务器端推送时间就能保证每个客户端的时间都是一致的。还有,比如间隔消息推送之类的需求。
若在服务器端处理的时候。若没有返回数据,在FF下会中断SSE连接,并且都不会在连接上了。
public function sse_connect() { header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); $result = D("Plan")->checkIsUpdate($_GET['planID'], $_GET['editTime']); if ($result == "update") { echo "event: update\n\n"; echo "data: {$result}\n\n"; ob_flush(); flush(); } }
因此必须每次连接都有返回数据才行。而在CHROME下则可以处理这种情况。没有返回也可以再次发起连接。
Fireforx上sse是每5秒发起一次连接。而chrome是3秒。
Chrome:
Sat Oct 12 2013 16:36:06 GMT+0800 (中国标准时间) article.js:2067 http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed article.js:2075
Sat Oct 12 2013 16:36:09 GMT+0800 (中国标准时间) article.js:2067 http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed article.js:2075
Sat Oct 12 2013 16:36:12 GMT+0800 (中国标准时间) article.js:2067 http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed article.js:2075
Sat Oct 12 2013 16:36:16 GMT+0800 (中国标准时间) article.js:2067 http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed
Firefox:
Date {Sat Oct 12 2013 16:36:29 GMT+0800}
article.js (line 2067) http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed
article.js (line 2075)
Date {Sat Oct 12 2013 16:36:34 GMT+0800}
article.js (line 2067) http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed
article.js (line 2075)
Date {Sat Oct 12 2013 16:36:39 GMT+0800}
article.js (line 2067) http://pageplan/Portal/Article/sse_connect?planID=147&editTime=2013-10-12%2016:31:29connection is closed
SSE的缺点是,定制性不高,API的参数很少,比如不能自定义轮询的时间间隔。
它本质上就是轮询get 类型的AJAX。
在特定的需求下会比较有用,比如做个时间显示。如果用JS写,不能保证时间一致,用服务器端推送时间就能保证每个客户端的时间都是一致的。还有,比如间隔消息推送之类的需求。
相关文章推荐
- new Date()再chrome和firefox下面的不同表现
- Javascript 在IE和FireFox中的不同表现
- HTML5视频方案:支持iPad Safari、Firefox、Chrome、IE9876
- Javascript在IE和FireFox中的不同表现简析
- Javascript 在IE和FireFox中的不同表现
- Javascript在IE和FireFox中的不同表现
- Javascript在IE和FireFox中的不同表现
- 解决struts2 下载中文名称乱码问题 适应不同三大主流浏览器 chrome28.0.1500.95、 firefox 23.0.1 、 IE11
- ul在Firefox和IE下的不同表现
- HTML5全屏API在FireFox/Chrome中的显示差异(转)
- 用HTML5为你的网页添加音效(兼容Firefox 3.5+, IE 6-9, Safari 3.0+, Chrome 3.0+, Opera 10.5+)
- ul在Firefox和IE下的不同表现的解决方法
- input在Firefox和Chrome中高度不同的解决办法
- alert 在firefox chrome ie8下面的表现
- chrome和Firefox浏览器渲染页面的不同
- ul在Firefox和IE下的不同表现的解决方法
- getAttribute在IE、Firefox中获取事件函数的不同表现
- Javascript在IE和FireFox中的不同表现
- HTML5视频方案:支持Ipad Safari、Firefox、Chrome、IE9876
- js传递给NPAPI插件的整数参数在firefox和chrome需要采用不同的获取方式