What is the disadvantage of using websocket/socket.io where ajax will do?

后端 未结 8 1613
余生分开走
余生分开走 2020-12-07 11:30

Similar questions have been asked before and they all reached the conclusion that AJAX will not become obsolete. But in what ways is ajax better than websockets?

Wit

8条回答
  •  不知归路
    2020-12-07 11:59

    As other people said, keeping the connection open can be overkill in some scenarios where you don't need server to client notifications, or client to server request happens with low frecuency.

    But another disadvantage is that websockets is a low level protocol, not offering additional features to TCP once the initial handshake is performed. So when implementing a request-response paradigm over websockets, you will probably miss features that HTTP (a very mature and extense protocol family) offers, like caching (client and shared caches), validation (conditional requests), safety and idempotence (with implications on how the agent behaves), range requests, content types, status codes, ...

    That is, you reduce message sizes at a cost.

    So my choice is AJAX for request-response, websockets for server pushing and high frequency low latency messaging

提交回复
热议问题