So I know that HTTP is basically just a text protocol over TCP, and that TCP is state / connection based. That means that the browser has to connect over TCP to a server before doing an HTTP request. Question then: do browsers typically create a new TCP connection for each HTTP request?

Browsers could just open a TCP request and keep it alive as long as the user is still browsing on that server, but then servers would have to use a big amount of maximum connections to handle that. But then again, if the browsers create a connection for each request, and the user browses a lot on the same server, that would seem like a waste. How does it usually work? Maybe through use of a timer?

link|improve this question
feedback

2 Answers

up vote 6 down vote accepted

In HTTP/0.9 (not used anymore), each request uses a separate TCP connection, and the end of a response is signalled by closing the connection.

In HTTP/1.0, an unofficial but very widely supported "Connection: Keep-Alive" request header can be used to request a persistent connection if the server supports it.

In HTTP/1.1, persistent connections are the default, and the old single-request behavior has to be requested explicitly.

Resources: Wikipedia article and RFC 2616 section 8.1.

See also: HTTP pipelining (another HTTP speed improvement) and SPDY (an alternative protocol proposed by Google).

link|improve this answer
feedback

There is "Connection: Keep-Alive" header. See enwiki for details.

You can use Wireshark to capture and analyse connections and see all headers.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.