Answer the question
In order to leave comments, you need to log in
When should I use ajax and when should I use websocket?
There is a script which sends request and should receive the answer.
He can get an answer (say) within 5 minutes.
The question is, from what considerations should one proceed when choosing between "ajax request to the server once every N seconds" or "opening a websocket"?
In my opinion (non-professional front-end developer), a web socket is preferable, since the client will instantly receive a response as soon as it appears on the server, and this can be pleasant for the user, since the appearance of data on the server is the result of an action in the user’s mobile application and is pleasant (although not critical) to see the result immediately, and not after N seconds.
There will be exactly one response from the user, that is, after receiving it, the script exits.
I would like to hear the negative sides of the websocket
Answer the question
In order to leave comments, you need to log in
I would like to hear the negative sides of the websocket
The negative side of the websocket is the lack of delivery guarantees. The package may get lost, the connection may break, and the parties will not notice. ajax provides delivery guarantees at the protocol level.
It makes no sense for you to use sockets for 1 request. On ajax, you can not only make requests by interval, read about long polling
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question