The HTTP keep-alive parameter is used within the HTTP/1.1 protocol to control the connection behavior between a client (e.g., a web browser) and a server. Its purpose is to improve the performance and efficiency of the communication between them by allowing multiple data exchanges (multiple requests and responses) over a single TCP connection, without having to open and close a new connection for each request.
Before the introduction of keep-alive in the HTTP/1.1 protocol, a new TCP connection was opened for each request, which increased response time and server load. With the use of keep-alive, a client and server can use one connection to transfer multiple requests and responses, reducing response time and server load.
The keep-alive parameter is typically set in the HTTP headers of a request or response. For example, a server may send a header named Connection with the value keep-alive as part of the response to a client's request, indicating that the connection should not be closed after sending the response.
In the HTTP/2 protocol, keep-alive is implicitly enabled, meaning it does not need to be explicitly set in the headers because the protocol already allows multiple data exchanges within a single TCP connection.