In this lesson, you checked which of the hero’s thirteen files the browser actually chose, in the Network panel and with the image’s currentSrc, and saw Chrome keep a larger file when the window got narrower.
Key Points
- The page can’t tell you. Apart from the square crop on small screens, the hero looks the same whichever file arrives, so your arithmetic is only a prediction. At 1280 pixels on a screen with a density of 1, the hero’s slot is 778 pixels wide. Current Chrome takes the AVIF source, and its smallest file that’s wide enough is
plot-7-800.avif. - The Network panel lists every file the page downloads, with its name, its type and its size. It records while DevTools is open, and each reload starts the list afresh. Tick Disable cache first, so every reload fetches the files again, as a first visit would. Click Img to list images only. At 1280 pixels, one row appears for the hero:
plot-7-800.avif, about 82 kB, the file your arithmetic picked. currentSrcnames the file the image is showing right now. In the Console,documentis the page.document.querySelector(".hero img")finds the first element that matches the CSS selector.hero img, and itscurrentSrcis the address of the file that element shows. Reading it changes nothing on the page.- A narrowed window keeps the larger file. Drag device mode down to 768 pixels, and the slot shrinks to 446 pixels, so your arithmetic gives
plot-7-480.avif. Will the browser download that file? No. No new row appears in the Network panel, andcurrentSrcstill ends inplot-7-800.avif. - Chrome keeps the sharper file. The page already shows a file sharper than the slot needs. A smaller file would mean a second download for a softer photo, so Chrome keeps the one it has. That’s what it means for
srcsetto be a hint, not a command. - Load the page fresh to see what a screen gets. Reload at 768 pixels with the cache disabled, and the Network panel shows
plot-7-480.avif, about 34 kB instead of 82, andcurrentSrcagrees. - Density works the same way. Device mode’s DPR menu, short for device pixel ratio, makes the page act as if the screen had that density. If it’s not in the toolbar, turn it on from the toolbar’s More options menu (Add device pixel ratio).
- Changing the density needs a reload too. Set the DPR menu to 2, and nothing downloads, this time for a different reason. Chrome doesn’t fetch a new file when the density changes on an open page, so reload. After the reload, the slot needs 446 × 2 = 892 image pixels, and the Network panel shows
plot-7-1200.avif.
The Rule
- Load the page fresh, with the cache disabled, at each width and density you care about. The Network panel shows which file downloaded, and
currentSrcshows which file the image displays. - Your arithmetic tells you what the browser is likely to pick. These two tell you what it did.