為什么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