Sub topic 15
Watching it happen with DevTools and curl
This chapter assumes you know the stages of a page load from earlier chapters: URL parsing, DNS, TCP, TLS, HTTP, parsing, and rendering. You also need a terminal with curl and dig, and a Chromium-based or Firefox browser. The goal is to find each stage in real tool output, so you can check claims instead of taking them on trust.
Two vantage points
DevTools shows what the browser did. curl and dig show what the network and servers do when you take the browser out of the loop. Each has blind spots, so use both.
| Tool | Shows | Does not show |
|---|---|---|
| DevTools Network panel | Timing per request, cache hits, redirects, initiator, headers as the browser saw them | Raw packets, the TLS record contents |
| DevTools Performance panel | Parsing, style, layout, paint, compositing | Anything about the network path |
| `curl -v` | DNS result used, TCP connect, TLS handshake summary, raw headers | Rendering, subresources, cookies from your browser profile |
| `dig` | Records from a chosen DNS server, TTLs | The resolver cache your browser or OS used |
Reading the Network panel
Open DevTools (F12, or Ctrl+Shift+I / Cmd+Option+I), choose the Network tab, and reload the page. Open it before you navigate, because requests that happen while it is closed are not recorded.
Two settings make the output more useful:
- Disable cache (checked) forces full network requests. Use it to see the cold path. Uncheck it to see the warm path, where cached responses show
(memory cache)or(disk cache)in the Size column. - Preserve log keeps entries across navigations. Without it, a redirect chain is wiped as the next page loads, and you will only see the last request.
The first row is the document request. Each later row is a subresource (CSS, script, image, font), and the Initiator column tells you which document or script caused it. This is how you connect the tool back to the parsing chapter: a stylesheet's initiator is the HTML parser, while a late image may have been started by your JavaScript.
The waterfall and the Timing tab
Click a request and open Timing. The phases map directly onto the stages you have studied.
| Timing phase | Stage it measures |
|---|---|
| Queueing, Stalled | Waiting for a free connection slot or a higher-priority request |
| DNS Lookup | Resolving the host name |
| Initial connection | TCP three-way handshake |
| SSL | TLS handshake (included within Initial connection in Chromium) |
| Request sent | Writing the request to the socket |
| Waiting for server response | Time to first byte (TTFB) |
| Content Download | Receiving the response body |
When a connection is reused, DNS, Initial connection and SSL are absent for that request. That is not a bug. It is HTTP keep-alive, or HTTP/2 multiplexing, doing its job. Only the first request to an origin pays for setup.
The same numbers are available from script through the Navigation Timing API. Paste this into the Console after the page has loaded:
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 time in modern browsers. If the connection was reused or DNS was cached, the differences are 0. Zero means "this stage did not happen for this load", not "this stage was instant".
Headers, redirects and caching in the panel
The Headers tab shows the request line, status, and both header sets. Check these:
Content-TypeandContent-Encodingtell you how to interpret the body.Cache-Control,ETagandLast-Modifiedexplain why a later reload is served from cache or revalidated with a304 Not Modified.Locationon a 301, 302, 307 or 308 response shows where the browser went next. Each hop appears as its own row when Preserve log is on.- The Protocol column (right-click the column header to enable it) shows
http/1.1,h2orh3.
A status of 200 with a Size of (disk cache) means no request left the machine. A 304 with a small size means a request was made, the server confirmed the cached copy was still valid, and no body was sent. These look similar in the waterfall but behave differently on the network.
Hard reload versus normal reload
A normal reload (F5) revalidates cached resources. A hard reload (Ctrl+Shift+R) bypasses the cache for the page's resources. With DevTools open, the reload button's context menu also offers "Empty cache and hard reload". Use these to compare the warm and cold paths for the same URL.
Observing DNS with dig
The browser's resolution is hidden, but you can query the same system yourself.
dig +short example.com A
dig example.com NSThe first command prints only the IPv4 addresses. The second shows the name servers responsible for the domain. Add +trace to follow the delegation from the root servers down, and @1.1.1.1 to ask a specific resolver. In the full dig output, the number before IN in each answer is the remaining TTL in seconds. Run the same query twice against a caching resolver and you will see the TTL count down, which is the cache at work.
Keep in mind that dig talks to DNS directly. The browser may instead use its own cache, the OS resolver, the hosts file, or DNS over HTTPS. If dig and the browser disagree, one of those layers is the likely cause.
Observing the connection with curl
curl -v https://example.com/ -o /dev/null-v prints diagnostics to stderr, and -o /dev/null discards the body so the output is readable. Lines starting with * describe connection events, > lines are the request curl sent, and < lines are the response received. Read the output top to bottom:
* Host example.com:443 was resolved.and theIPv4:orIPv6:lines show the DNS result.* Connected to example.com (...) port 443marks the TCP handshake completing.* TLSv1.3 (OUT), TLS handshake, Client helloand the following lines show the TLS negotiation, the chosen cipher, and the certificate subject, issuer and validity dates.> GET / HTTP/2and the headers that follow are the request.< HTTP/2 200and the headers that follow are the response.
The exact wording varies by curl version, but the order does not.
Several flags help isolate a stage:
-Isends a HEAD request, so you get only headers.-Lfollows redirects. Without it, curl stops at the 3xx response and you can readLocationyourself.--http1.1,--http2and--http3force a protocol version, if your build supports it.--resolve example.com:443:203.0.113.10skips DNS and connects to the address you give, which is useful for testing a server before DNS changes.--connect-timeout 5limits how long the TCP stage may take.
Timing breakdown with --write-out
For numbers instead of a transcript, use -w with timing variables:
curl -s -o /dev/null https://example.com/ -w 'dns: %{time_namelookup}s\nconnect: %{time_connect}s\ntls: %{time_appconnect}s\nttfb: %{time_starttransfer}s\ntotal: %{time_total}s\n'These values are cumulative from the start of the request, not per-phase durations. To get the TLS cost, subtract time_connect from time_appconnect. To get server think time, subtract time_pretransfer from time_starttransfer.
Common mistakes when reading the output
- Comparing curl to the browser directly. curl sends no cookies, a different
User-AgentandAccept-Encoding, and does not run JavaScript. A server may answer curl differently, for example with a bot challenge or an uncompressed body. - Forgetting
-L. A301fromhttp://tohttps://looks like a failure when it is the redirect you expected. - Treating a single measurement as typical. DNS caches, connection reuse and server load change the numbers. Repeat the measurement several times and compare medians.
- Reading
time_connectas the whole setup cost. On HTTPS, the TLS handshake comes after it. - Misreading a cache hit. A request missing from the server's logs may have been satisfied by the browser's cache, not lost.
Observing parsing and rendering
The Network panel stops at the response. For the rest, use the Performance panel: record a reload, then look at the main thread track. You will see Parse HTML, Recalculate Style, Layout, Paint and Composite Layers as labeled blocks, along with markers for First Contentful Paint and DOMContentLoaded. A <script> without defer or async shows up as a long block that interrupts Parse HTML, which is the parser-blocking behaviour from the earlier chapter made visible. The Elements panel shows the DOM as it exists now, not the HTML that was sent, so scripts that change the page make the two differ. Use View Source or the raw response in curl to see the original text.
Putting it together
A good habit is to take one URL and trace it end to end:
- Run
dig +shorton the host and note the address. - Run
curl -vand match the resolved address, the TLS details and the status line. - Run the
-wtiming command three times and note which stage varies most. - Load the page in the browser with Disable cache on, and compare the Timing tab for the document request with curl's numbers.
- Reload with the cache on and note which rows become cache hits or
304responses. - Record a Performance trace and find where the first paint happens.
Exercise
In the Network panel, the document request shows 0 ms for DNS Lookup, Initial connection and SSL, yet the page loaded from the network (not the cache). Give two plausible reasons, and name one curl flag that lets you test the cold-DNS case against a specific address.
Show answer
Either the browser already had a cached DNS answer for the host, or it reused an existing open connection to that origin (keep-alive, or an HTTP/2 or HTTP/3 connection already established by an earlier request). Zero means the stage did not occur for this request. To control DNS, use --resolve host:port:address, which makes curl connect to a chosen IP without a DNS lookup.
Exercise
A curl -w run reports time_connect=0.040, time_appconnect=0.120 and time_starttransfer=0.300. How long did the TCP handshake, the TLS handshake and the server wait take, assuming time_pretransfer is 0.120 and DNS time is negligible?
Show answer
The values are cumulative. TCP took about 0.040 s (timeconnect). TLS took 0.120 - 0.040 = 0.080 s. Server wait took 0.300 - 0.120 = 0.180 s (timestarttransfer minus time_pretransfer).