Also available to read on dev.to
Having a smaller website makes it load faster — that's not surprising.
What is surprising is that a
14kb page can load much faster than a
15kb page — maybe
612ms faster — while the difference between a
15kb and a
16kb page is trivial.
This is because of the TCP slow start algorithm. This article will cover what that is, how it works, and why you should care. But first we'll quickly go over some of the basics.
Transmission Control Protocol (TCP) is a way of using the Internet Protocol (IP) to send packets of data reliably — sometimes this is referred to as TCP/IP.
When a browser requests your website (or an image or a stylesheet) it makes that request using HTTP.
HTTP is built on top of TCP and a single HTTP request is usually made up of many TCP packets.
On its own IP is just a system for sending packets of data from one location on the internet to another. IP doesn't have a way of checking if a packet has successfully arrived at its destination.
When it comes to websites, knowing that all the data has arrived is important — otherwise we could end up with missing chunks of web page. There are other used of the web where this doesn't matter so much — like streaming live video.
TCP is an extension of IP that allows a browser and your website's server to tell each other which packets have successfully arrived.
The server sends some packets, then waits for a response from the browser saying it has received the packets (this is called an acknowledgement or ACK), then it sends some more — or if it hasn't received an ACK it can send the packets again.
TCP slow start is an algorithm used by servers to find out how many packets it can send at a time.
When a browser first makes a connection to your server — the server has no way of knowing the amount of bandwidth between them.
Bandwidth is how much data can be transmitted over a network per unit of time. Usually it's measured in bits per second (
b/s). Plumbing is a common analogy — think of bandwidth as how much water can come out of a pipe per second.
Your server doesn't know how much data the connection can handle — so it starts by sending you a small and safe amount of data — usually 10 TCP packets.
If those packets successfully reach your site's visitor, their computer sends back an acknowledgement (ACK) saying the packets have been received.