Site AI Auditαπό την Internet Solutions

HTTP Keep-Alive and Connection Reuse: Why It Speeds Up Sites

22 Οκτωβρίου 20268 λεπτά ανάγνωσηςΤαχύτητα ιστοτόπου
HTTP Keep-Alive and Connection Reuse: Why It Speeds Up Sites

Short answer: HTTP keep-alive lets the browser and server reuse one connection for many requests instead of opening a new one for every file. Each new connection costs a TCP handshake and, on https, a TLS handshake, which add round trips before any data arrives. Keep-alive is on by default in modern servers, but short timeouts, disabled settings, proxies and many separate hostnames can cancel the benefit. Check your waterfall for reused connections and review the server timeout.

What a connection costs

Before a browser can ask for a page, it has to reach the server. On an https site, that takes several steps. First comes a DNS lookup to find the address. Then a TCP handshake, which needs one round trip between the visitor and the server. Then a TLS handshake, which agrees on encryption and takes one more round trip with TLS 1.3, or two with TLS 1.2. Only after all that does the first request travel.

A round trip is the time for a message to go to the server and the answer to come back. On a fast broadband line to a nearby server it may be 10 to 30 milliseconds. On mobile or to a distant region, 100 milliseconds or more is common. Two or three round trips before the first byte can easily cost a quarter of a second. If that price were paid for every image, script and stylesheet, pages would be very slow.

What keep-alive does

Keep-alive, also called a persistent connection, keeps the connection open after a response so that the next request can use it. The browser pays the setup cost once and then sends many requests over the same connection. In HTTP/1.1, persistent connections are the default; the server closes them only when it says so with a “Connection: close” header or when the idle timeout expires.

HTTP/2 goes further. It uses a single connection per hostname and sends many requests at once on it, a feature called multiplexing. This makes reuse even more important, because everything on that hostname depends on one connection. Our guide to HTTP/2 and HTTP/3 explains the differences in detail.

Why reuse sometimes fails

Many websites have keep-alive switched on in theory but lose much of the benefit in practice. These are the usual reasons.

How to check reuse in your waterfall

Run your page in a speed test tool that shows a request waterfall. Each row represents one file, and the coloured bars within it show the stages: DNS, connect, TLS, waiting and download. For a reused connection, the DNS, connect and TLS stages are absent. Our article on reading a waterfall chart explains the colours.

Check two things:

  1. The first request to your own domain should show the connection stages. All later requests to the same domain should not. If they do, the connection is not being reused.
  2. Count how many connection stages appear in total. Each one is a different hostname or a connection that was closed. The fewer you have, the better.

You can also look at the response headers in your browser developer tools. A “Connection: keep-alive” header in an HTTP/1.1 response shows that the server allows reuse, while “Connection: close” shows that it does not. With HTTP/2 the header is not used, because reuse is built in. Check the protocol column in the network panel to see which one you have.

An example of the difference

Suppose a page needs 40 files from your own domain, and each new connection would cost 120 milliseconds of setup on a mobile network. If the browser opened a separate connection for every file, even with six at a time, it would pay that price several times before the page is ready. With one reused connection, it pays once and then spends its time downloading.

Real browsers already limit the damage by opening a handful of parallel connections, and HTTP/2 combines requests on one. That is why the gain is not always dramatic in a lab test. It shows up most clearly on slow mobile networks, on distant visitors and on servers with a very short idle timeout, where every page view quietly starts from zero. When a visitor clicks to the next page a few seconds later, a connection that is still open saves the whole setup again.

This is also why a test that you run only once can mislead. Run it from a mobile profile, repeat it twice and compare the connection stages of the first and the second view. If the second view still shows full connection stages for your own domain, the server is closing connections too early or something between the visitor and the server is doing it.

How to configure it

If you manage your own server, review these settings. If you use shared hosting, ask your provider or check the control panel, since most managed hosts have sensible defaults.

Always change one setting at a time and measure the result. Very long timeouts on a small server can use all available memory under heavy traffic, which makes the site slower, not faster. For a comparison of servers and their defaults, see nginx, Apache and LiteSpeed compared.

Other ways to reduce connection cost

Keep-alive saves the cost of repeated connections but does not remove the first one. Combine it with other measures:

What Site AI Audit can and cannot tell you

Site AI Audit’s speed results include the Google PageSpeed score, LCP, CLS and INP, server response time and the compression and weight of your pages. It does not report whether individual connections were reused, so use a waterfall for that detail. If the response time is high on a page with little content, connection setup and server delay are the first things to examine. You can run a free check of your website or see the plans.

Related reading

The bottom line

Every new connection costs round trips, so reusing connections is one of the cheapest speed improvements available. Keep keep-alive enabled, choose a sensible idle timeout, avoid needless hostnames and check the waterfall to confirm that later requests skip the connection stages. Combine this with TLS 1.3 and a CDN for the best effect.

FAQ

Is keep-alive enabled by default?

In HTTP/1.1 it is the default behaviour, and most servers enable it. Check your configuration and timeout, because the defaults vary.

Does HTTP/2 make keep-alive unnecessary?

No. HTTP/2 relies on a long-lived connection and multiplexes requests over it, so connection reuse matters even more.

Can keep-alive slow down my server?

If timeouts are very long on a small server, idle connections can use up memory or workers. Choose a moderate timeout and monitor.

How do I see if connections are reused?

Use a request waterfall. Reused connections show no connect or TLS stage for later requests to the same hostname.

Do I need to change anything on shared hosting?

Usually not. Hosts normally configure it well. If your waterfall shows new connections for every file, ask the provider.

#Page speed#Speed testing#Web hosting
Ελέγξτε τον δικό σας ιστότοπο — δωρεάν.Τι να διορθώσετε στον ιστότοπό σας — και από πού να ξεκινήσετε.
Ξεκινήστε δωρεάν

Περισσότερα από το blog

Όλα τα άρθρα →
Internet Solutions

Περισσότερα από την ομάδα μας

Από την Internet Solutions. Δοκιμάστε και τα άλλα προϊόντα μας — το καθένα σας εξοικονομεί χρόνο με διαφορετικό τρόπο.

internet-solutions.net ↗
01Αυτόματες αναρτήσεις στα social
PostRSS

Οι νέες αναρτήσεις από τη ροή RSS σας πηγαίνουν αυτόματα σε Facebook, X, LinkedIn, Telegram και σε 60+ ακόμη δίκτυα.

Δωρεάν πλάνο · από το 2014Επίσκεψη →
02Ζωντανή συνομιλία AI για ιστοσελίδες
Talkmio

Η ιστοσελίδα σας απαντά στους επισκέπτες 24/7 από το δικό σας περιεχόμενο, στη γλώσσα τους.

Δωρεάν πλάνο · χωρίς κάρταΕπίσκεψη →
03AI βοηθός
Ask Mio

Συνομιλία, κώδικας, σχεδιασμός, γραφή και έρευνα. Το Mio επιλέγει το καλύτερο μοντέλο για κάθε εργασία.

Δωρεάν πλάνοΕπίσκεψη →
04AI αυτόματος πιλότος για blog και social
AI Blog Autopilot

Η AI γράφει άρθρα SEO 2.000–3.000 λέξεων και κοινοποιεί το καθένα σε 60 κοινωνικά δίκτυα.

Τα 3 πρώτα άρθρα δωρεάνΕπίσκεψη →
05Σε βάθος SEO crawl
Site SEO AI Audit

Πλήρες SEO crawl σε 7 τομείς, μαζί με την ορατότητα στην αναζήτηση AI, με διορθώσεις ταξινομημένες κατά αντίκτυπο.

Ο πρώτος έλεγχος δωρεάνΕπίσκεψη →
06Ροές RSS και προϊόντων
RSS Feed Creator

Δημιουργήστε RSS από οποιαδήποτε ιστοσελίδα, καθώς και ροές προϊόντων για Google και Meta που ενημερώνονται μόνες τους.

Δωρεάν πλάνοΕπίσκεψη →
07Ανάπτυξη ιστοσελίδων και SEO
Internet Solutions

Ιστοσελίδες, e-shops και εξειδικευμένα συστήματα — τα σχεδιάζει, τα αναπτύσσει και τα υποστηρίζει η ομάδα μας.

Από το 2011Επίσκεψη →