为什么HTTP2的服务端推送不能代替websocket


Well, to quote from this InfoQ article:

Well, the answer is clearly no, for a simple reason: As we have seen above, HTTP/2 introduces Server Push which enables the server to proactively send resources to the client cache. It does not, however, allow for pushing data down to the client application itself. Server pushes are only processed by the browser and do not pop up to the application code, meaning there is no API for the application to get notifications for those events.

And so HTTP2 push is really something between your browser and server, while Websockets really expose the APIs that can be used by both client (javascript, if its running on browser) and application code (running on server) for transferring real time data.

 
 
因为HTTP2的推送是浏览器和服务端之间的一个推送的概念,比如我在HTTP2中请求 a.html 服务端会自动把css和一些其他资源一并返回,
而websocket的推送是有API的,可以在客户端手动控制的,这就是区别。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM