Keep-alive is an HTTP feature that reuses one connection for several files instead of opening a new one each time.
Keep-alive, also called a persistent connection, lets a browser download many files over the same connection to a web server. Without it, the browser has to open a fresh connection for every single file: the HTML, each stylesheet, each script and each image.
A typical page loads dozens of files. Opening a new connection for each one adds a delay every time, because the browser and server have to set it up first. With keep-alive, that setup happens once and the connection stays open for the rest of the page.
How keep-alive works
- The browser connects to the server and completes the TCP handshake, plus the TLS handshake for HTTPS.
- It requests the first file, usually the HTML page.
- Instead of closing the connection, the server keeps it open.
- The browser sends the next request over the same connection, and so on.
- The connection closes after a period of inactivity, set by the server's keep-alive timeout.
In HTTP/1.0, keep-alive had to be requested with a Connection: keep-alive header. In HTTP/1.1, connections are persistent by default. HTTP/2 and HTTP/3 go further, sending many requests at the same time over a single connection.
Why keep-alive matters for your website
Every new connection costs at least one round trip between the visitor and the server, and HTTPS adds more. On a mobile connection, or for a visitor far from your server, each round trip can take a noticeable fraction of a second. Reusing connections cuts that overhead, which improves load times and time to first byte for later files. It also reduces work for the server.
Keep-alive settings
Hosts usually configure two values:
- Timeout: how long an idle connection stays open, often a few seconds.
- Maximum requests: how many requests one connection can handle before it's closed.
A timeout that's too long can tie up server resources with idle connections. Too short, and browsers have to reconnect more often. Modern event-driven servers like LiteSpeed handle large numbers of open connections cheaply, so they can keep connections alive without much cost.
How to check if keep-alive is enabled
Open your browser's developer tools, go to the Network tab and look at the connection ID column, or check the response headers for Connection: keep-alive. On HTTP/2 or HTTP/3 you won't see the header, because those protocols reuse connections automatically. Online speed tests often report it too.
On shared hosting you usually can't change the setting yourself, and you shouldn't need to. If a test says keep-alive is off, ask your host. Combined with GZIP compression and a cache, it's one of the basics of a fast site.