Sub topic 15
Watching it happen with DevTools and curl
This chapter assumes you have read the earlier chapters on URLs, DNS, TCP, TLS, HTTP and rendering. It maps each stage to a tool that shows it. You need a Chromium-based or Firefox browser and a terminal with dig and curl.
Where each stage shows up
Each stage leaves evidence somewhere. The table below says where to look.
| Stage | Where to observe it |
|---|---|
| DNS | `dig`, the Timing tab in DevTools |
| TCP and TLS | `curl -v`, the Timing tab |
| HTTP request and response | `curl -v`, the Headers tab |
| Caching | The Size column in the Network panel |
| Parsing and rendering | The Performance panel, Navigation Timing |
Observing DNS with dig
dig sends a DNS query directly, so you see the answer without the browser's own cache.
dig +short example.com A
dig example.com NSThe first command prints the IPv4 addresses. The second shows the name servers responsible for the domain. The browser may use a different answer if its own cache or the operating system cache still holds an older one.
Observing the connection with curl -v
The -v flag prints each step on stderr. Discarding the body keeps the output readable.
curl -v https://example.com/ -o /dev/nullRead the output from the top:
- Lines starting with
*show the resolved address, the TCP connection and the TLS handshake, including the negotiated protocol and certificate details. - Lines starting with
>are the request headers curl sent. - Lines starting with
<are the response headers it received.
A request in the > lines looks like this:
GET /docs/intro?lang=en HTTP/1.1
Host: example.com
Accept: text/html
User-Agent: example-client
Connection: keep-aliveCompare it with the < lines, where you will find the status line and headers such as Content-Type and Cache-Control.
The Network panel
Open DevTools (F12), choose Network, then reload the page. Each row is one request. Check these parts first:
- Name and Status: the resource and its status code. A redirect appears as its own row with a 3xx status.
- Size:
(disk cache)or(memory cache)means the browser did not use the network. A normal size means a transfer happened. - Waterfall: bars show when each request started and how long it took. The HTML document comes first. Stylesheets, scripts and images start after the parser finds them.
- Timing tab: click a request to see the stages for that request, such as DNS lookup, initial connection, SSL, waiting (time to first byte) and content download.
Reused connections show no DNS, connect or SSL time. That is normal. It does not mean those stages were skipped for the whole page.
Timing from JavaScript
The Navigation Timing API gives the same numbers in code. Paste this into the Console after the page loads.
const [nav] = performance.getEntriesByType('navigation');
console.log('DNS ms:', nav.domainLookupEnd - nav.domainLookupStart);
console.log('Connect ms:', nav.connectEnd - nav.connectStart);
console.log('TTFB ms:', nav.responseStart - nav.requestStart);
console.log('DOMContentLoaded ms:', nav.domContentLoadedEventEnd - nav.startTime);Note that connectEnd - connectStart includes the TLS handshake. DNS and connect values are often 0 on a repeat visit because the browser reused a cached lookup or an open connection.
Common mistakes
- Trusting
digto match the browser. The browser can use its own cache, a DNS-over-HTTPS resolver or the hosts file. - Reading
curloutput as browser behavior. curl does not cache, run scripts or follow redirects unless you add-L. - Judging load speed by one request. Use the whole waterfall, because later requests depend on earlier ones.
Exercise
You reload a page and the Network panel shows 0 ms for DNS and connect on a stylesheet request. Name two possible reasons.
Show answer
The browser may have served the stylesheet from its cache, so no network request was made. Or it may have reused an open connection to the same host, so no new DNS lookup or TCP/TLS setup was needed.