completefrontend

Predict the outputMedium

What does the second load log for each file's transfer size?

The tea shop's page has a stylesheet, a picture of a teapot, and a script that fills in the menu. The server sends index.html with Cache-Control: no-store and every other file with Cache-Control: max-age=31536000. You open the page once, close the tab, and open it again in a new tab. When the second load's load event fires, the page logs what Resource Timing says about each file, and what Navigation Timing says about the page itself. What does it log?

index.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Leaf and Kettle</title>
  <link rel="stylesheet" href="shop.css">
</head>
<body>
  <h1>Leaf and Kettle</h1>
  <img src="teapot.svg" alt="A copper teapot" width="320" height="200">
  <ul id="menu"></ul>
  <script src="menu.js"></script>
  <script>
    addEventListener("load", () => {
      const resources = performance.getEntriesByType("resource");
      // One line per file, in a fixed order, so every load logs the same lines.
      for (const file of ["shop.css", "teapot.svg", "menu.js"]) {
        const entry = resources.find((item) => item.name.endsWith("/" + file));
        if (!entry) {
          console.log(file + ": no entry");
          continue;
        }
        const body = entry.encodedBodySize > 0 ? "above 0" : "0";
        console.log(`${file}: transferSize ${entry.transferSize}, encodedBodySize ${body}, deliveryType "${entry.deliveryType}"`);
      }
      const [page] = performance.getEntriesByType("navigation");
      const size = page.transferSize > 300 ? "above 300" : "300 or less";
      console.log(`index.html: transferSize ${size}, deliveryType "${page.deliveryType}"`);
      console.log(`index.html: transferSize minus encodedBodySize: ${page.transferSize - page.encodedBodySize}`);
    });
  </script>
</body>
</html>
shop.css
body { margin: 0; padding: 16px; font-family: system-ui, sans-serif; color: #2f3b2a; }
h1 { margin: 0 0 12px; color: #3f6f31; }
img { display: block; max-width: 100%; height: auto; }
teapot.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 200" width="320" height="200">
  <rect width="320" height="200" fill="#f4ead8"/>
  <ellipse cx="160" cy="120" rx="70" ry="50" fill="#b0602a"/>
  <rect x="135" y="58" width="50" height="16" rx="6" fill="#8a4a20"/>
  <path d="M90 110 Q50 100 60 140" stroke="#b0602a" stroke-width="10" fill="none"/>
  <path d="M230 105 Q275 90 262 60" stroke="#b0602a" stroke-width="10" fill="none"/>
</svg>
menu.js
// Fills in this week's teas.
const teas = ["Mint", "Oolong", "Rooibos"];
document.getElementById("menu").innerHTML = teas.map((tea) => "<li>" + tea + "</li>").join("");

Chrome loads these files from a server on the same computer, index.html at /, in a fresh profile with an empty cache, on a phone's screen (412 by 823 CSS pixels), with no network or CPU slowdown. It's a returning visit: the page was loaded once before, and every file but index.html may come from the cache.

  1. You open the page in Chrome, wait for it to load, and close the tab.
  2. You open the page again in a new tab, in the same browser profile.
  3. When the second load's load event fires, the page's script logs what it found.

Practice it in the editor, with tests

The answer

Work out what Chrome does with the page: every line it logs, in order, and how it treats each file. Then check.

Checking your sign-in…