Keep-Alive
HTTP is built on top of Transmission Control Protocol (TCP). In
early implementations of HTTP, each HTTP request required opening a new
socket connection. This is inefficient because many HTTP requests in a
web page go to the same server. For example, most requests for images in
a web page all go to a common image server. Persistent Connections (also known as
Keep-Alive in HTTP/1.0) was
introduced to solve the inefficiency of opening and closing multiple
socket connections to the same server. It lets browsers make multiple
requests over a single connection. Browsers and servers use the Connection header to indicate Keep-Alive
support. The Connection header looks
the same in the server's response.
GET /us.js.yimg.com/lib/common/utils/2/yahoo_2.0.0-b2.js HTTP/1.1 Host: us.js2.yimg.com User-Agent: Mozilla/5.0 (...) Gecko/20061206 Firefox/1.5.0.9 Accept-Encoding: gzip,deflate Connection: keep-alive HTTP/1.1 200 OK Content-Type: application/x-javascript Last-Modified: Wed, 22 Feb 2006 04:15:54 GMT Connection: keep-alive
The browser or server can close the connection by sending a
Connection: close header.
Technically, the Connection:
keep-alive header is not required in HTTP/1.1, but most
browsers and servers still include it.
Pipelining, defined in HTTP/1.1, allows for sending multiple requests over a single socket without waiting for a response. Pipelining has better performance than persistent connections. Unfortunately, pipelining is not supported in Internet Explorer (up ...