How to maintain an HTTP role / plays a role in an AJAX application

"keep-alive" him there in HTTP. Some say that this should be good, but I cannot come to any conclusion. Therefore, please provide your input / response / submission, so that I can get some reasons for this,

  • What is he doing?
  • A scenario where this should and should not be done?
  • How to make the AJAX app better?
  • Risks of DO and DONT, if any?

    Thank you all for your input.

+7
javascript ajax
source share
3 answers

First of all, if your connection to the server uses HTTP / 1.1, then you most likely already use "keep-alive".

What is it? Logically, HTTP is a connectionless protocol. This every request / response to the server creates a new connection, makes it a business and disconnects the connection. However, in HTTP / 1.1, the default behavior is to keep the connection open for subsequent server requests. The "keep-alive" header was added in HTTP / 1.0 to enable this behavior; in HTTP / 1.1, the server should refuse by closing the connection itself and / or sending the "close connection" header in response.

Why is it profitable? Creating a connection, especially for authentication, may take some time. By reusing an existing connection, configuration and authentication efforts are greatly reduced.

How can he improve your AJAX application? You probably already benefited from this.

What are the risks? When connecting through a shared device that can connect to the server on behalf of the client, other clients can reuse the connection, however, it also allows other clients to use the connection that the server has authenticated to another user.

+12
source
  • It supports opening a TCP socket for a client, so you won’t reconnect to send another HTTP request;
  • Keep-live improves HTTP performance when there are many requests in the query string. It should not be used, however, if requests are rare (the server usually closes the connection if more requests are not received from the client for some period of time).
  • Well, if your AJAX application sends a lot of requests to server leaders, improve its performance.
  • There is a risk of server-side socket destruction, so the server has the right to interrupt even keep-alive connections.
+1
source

It really comes down to performance and resource issues.

Using high (er) support allows you to reduce the latency of requests. This is especially important if you are using SSL, where there are additional handshakes to establish a connection.

OTOH, this will mean that there are additional server processes. Walkers stand idle, expecting a subsequent request or keep-alive to expire. This can lead to memory failures and therefore slow down your server.

So, you really need to play around and see what is acceptable in terms of browser performance and server load.

Authentication (basic / digest / session) does not matter - this is an authentication request, not a socket connection.

Note that the last time I did a new installation of Apache, it turned on the default setting of 5 seconds to save. This is ridiculously long for a site without an ajax.

FROM.

+1
source

All Articles