Reputation: 2679
It is common knowledge now to combine stylesheets and scripts in effort to reduce HTTP Requests. I have 2 questions:
I cannot find the answers to these two questions in all online readings I did, such as Yahoo! Best Practices which states a number of times that HTTP requests are expensive, but never cite why or how.
Thanks in advance.
Upvotes: 9
Views: 2763
Reputation: 342635
Hope that makes sense.
Upvotes: 2
Reputation: 42008
A HTTP request requires a TCP/IP connection to be made (Think, 3-way handshaking handshaking) before it can handle the HTTP request it self
This involves at least a delay of sending the SYN message to the server and getting the SYN/ACK back (It then sends the ACK to OPEN the socket).
So, say the delay between the client and server is uniform both ways and 50ms, that results in a 100ms delay before it can send the HTTP request. It is then another 100ms before it starts getting the actual request back (Sends the request, then server replies).
Of course, you need to also take into consideration that a standard web browser limits the number of concurrent HTTP requests it is processing at the same time. If your requests have to wait, you don't get that handshake time for free (so to say), since you need to wait for another connection to finish as well. Servers play a role as well, depending on how they server the requests.
Upvotes: 6
Reputation: 375494
I don't have an answer for how expensive HTTP request are, but it is always a good idea to reduce roundtrips between the client and server. If you have a fixed amount of data to transmit, it will always be better to do it in fewer requests.
Upvotes: 1