DEV Community

Daniel Pertu
Daniel Pertu

Posted on

35 of our 38 pages answer a repeat visit in 300 bytes, and the three that cannot are the three with a price on

Notifio is a desktop rental alert app with a 38-page marketing site in front of it. I have written before about the three pages that tell every cache not to store them, which is a header-level fact. This post is the behavioural half: what actually crosses the wire when the same reader comes back, measured both with curl and in a real browser.

The sweep

For every URL in the sitemap, plus six static files, I did four requests: a plain GET, a GET with If-None-Match set to the ETag that came back, a GET with If-Modified-Since set to the Last-Modified that came back, and a GET with a deliberately wrong ETag.

URLs probed                        44  (38 pages + 6 assets)
Responses carrying an ETag         41
Responses carrying Last-Modified    6
304 to a matching If-None-Match    41
304 to If-Modified-Since            6
200 to a wrong ETag                44
Enter fullscreen mode Exit fullscreen mode

Three numbers in that block are the whole post.

41 ETags out of 44. The three without one are the home page, /pricing and /download. All three answer private, no-cache, no-store, max-age=0, must-revalidate and x-vercel-cache: MISS, because each of them prints a price resolved from the request, and a shared cache holding one visitor's currency is a worse bug than any amount of traffic. No stored response means no validator, and no validator means there is nothing a conditional request could match.

Six Last-Modified out of 44. Those six are exactly the static files: the stylesheet, the sitemap, robots.txt and the icons. Not one of the 35 cacheable HTML pages sends a date. The ETag is the only validator our HTML has, so a cache that only knows how to ask "has this changed since Tuesday" gets a full document every time. Browsers send both when they have both, so this costs nothing today. It is still a one-validator surface, and worth knowing before you debug a proxy that only does dates.

44 200s to a wrong ETag. That is the check that proves the 304s mean something.

What a 304 costs and what it saves

The 35 revalidatable pages are 1,991,036 bytes of HTML, a mean of 56,887 bytes each. Their 304 responses are 367 bytes each, nine headers, and they faithfully echo both the ETag and the Cache-Control the spec asks for.

Full HTML, 35 pages            1,991,036 bytes
Revalidating all 35              12,845 bytes   (35 x 367)
Ratio                                  155x
Enter fullscreen mode Exit fullscreen mode

The static assets answer in 235 bytes and six headers, which is the same mechanism with less framework noise in the header block.

Two ETags per URL, depending on what you ask for

The same page has two different validators depending on the encoding you accept:

Accept-Encoding: br         9,580 bytes   W/"ac71473108a1560f6339d87c98c56a74"
Accept-Encoding: gzip       9,426 bytes   W/"ac71473108a1560f6339d87c98c56a74"
Accept-Encoding: identity  53,832 bytes     "ac71473108a1560f6339d87c98c56a74"
Accept-Encoding: deflate   53,832 bytes     "ac71473108a1560f6339d87c98c56a74"
Enter fullscreen mode Exit fullscreen mode

Same hex digest, strong for the uncompressed body and weak for the compressed ones, which is correct: compression changes the bytes but not the meaning, so the validator weakens rather than changing. I measured the same behaviour on a sibling site last month, which is a reminder that this is the platform's answer and not something either codebase decided.

The gap is on the next line of the same response. None of these 44 URLs sends Vary: Accept-Encoding. The page responses vary on four Next.js router headers and nothing else; the static files send no Vary at all. One URL, two bodies, two validators, and no header telling a shared cache that the request headers mattered. Our own readers are fine, because the CDN in front of us is the thing doing the compressing and it keeps its variants straight. Anything else in the path is guessing.

deflate is also worth a look: asking for it gets the full uncompressed 53,832 bytes, because it is not on offer and the server correctly falls back rather than pretending.

The precondition that turns a GET into a 412

While I had the headers out, I tried the other conditionals:

Request header Status Body
If-None-Match: "<matching>" 304 0 bytes
If-None-Match: W/"<matching>" 304 0 bytes
If-None-Match: * 304 0 bytes
If-None-Match: "x", "<matching>" 304 0 bytes
If-Match: "nope" 412 79 bytes
If-Unmodified-Since: 1 Jan 1970 412 79 bytes
If-Modified-Since: 1 Jan 2099 200 53,832 bytes

The weak form, the wildcard and a list all work, which is more of RFC 9110 than most people ever exercise.

The two 412s are the interesting rows. A GET on a static marketing page answering "Precondition Failed" with a 79-byte body is spec-correct and not something anyone in this repository implemented or knew about. It is also harmless in practice, since nothing sends If-Match on a page read. If you have ever wondered whether your platform implements the write-side preconditions on your read-only pages, the answer is probably yes.

The last row is the Last-Modified gap showing up as behaviour: a date far in the future should produce a 304 if the server had a modification date to compare against. It has none, so it serves the document.

What a real browser does on the second visit

Headers are a promise. The thing I actually wanted was the transfer size on a repeat visit, which the Resource Timing API reports honestly. Three sequential navigations to the same URL in one browser context, no cache clearing:

Page Visit 1 doc Visit 2 doc Visit 3 doc Subresources from cache
/help 9,880 300 300 12
/alerts 10,511 300 300 11
/terms 12,874 300 300 11
/ 14,036 14,036 14,036 13
/pricing 6,485 6,485 6,485 12
/download 7,257 7,257 7,257 12

transferSize: 300 is what Chrome reports for a revalidated response: the 304 header block and no body, while encodedBodySize still reports the full 9,580 bytes that came out of the disk cache. The top three rows are the mechanism working exactly as designed.

The bottom three rows are the cost of the price. 14,036 plus 6,485 plus 7,257 is 27,778 compressed bytes, or 151,847 bytes of HTML, that move again on every single visit by the same person, forever. If those three could revalidate, the same three visits would be 900 bytes.

It does not stop at the document either. Next.js prefetches these pages as flight payloads, and scrolling a hub page fires dozens of them. Asking for the payloads directly:

/?_rsc=...          39,606 bytes   no ETag    no-store
/pricing?_rsc=...    6,582 bytes   no ETag    no-store
/download?_rsc=...  14,807 bytes   no ETag    no-store
/help?_rsc=...      24,478 bytes   "4e62f355c8b6c9afc55d40b25876807f"   HIT
Enter fullscreen mode Exit fullscreen mode

A further 60,995 bytes with no validator, on the three pages a reader is most likely to come back to. And note the last line: the payload has its own ETag, different from the document's, so the two halves of a page are two independently validated resources.

What I would change

Not the no-store policy. A cached price in the wrong currency is a support ticket and a refund, and the last thing I want is an intermediary serving euros to somebody in London.

The honest fix is narrower: those three pages are each one small per-visitor fragment inside a large static document. The price could arrive as its own tiny uncacheable request inside a page that caches like every other page, which would turn 27,778 bytes a visit into roughly 300 plus a few hundred. That is a real change to how the pricing page renders, which is why it is written down here rather than deployed today.

Takeaways

  • no-store does not just cost you a cache hit, it costs you the conditional request too. There is no stored response, so there is no validator, so every repeat visit is a full download.
  • Measure the second visit, not the first. performance.getEntriesByType("navigation")[0].transferSize is 300 on a revalidated document and the full body on one that cannot revalidate, which makes the difference a one-line check.
  • Check whether your HTML sends Last-Modified at all. ETag-only is fine for browsers and invisible until something in the path only speaks dates.
  • If your CDN compresses for you, look for Vary: Accept-Encoding. You can end up with one URL, two bodies, two ETags and nothing in the response saying so.
  • Try If-Match once against your own site. Finding out that your static pages answer 412 is a thirty-second experiment and tells you who is really handling your headers.

Everything measured here is live: the alerts hub and help page that answer in 300 bytes, the pricing and download pages that cannot, and the guides if you would rather read about rentals than headers.

Top comments (0)