Sub topic 16
File-Size Budgets and Page Performance
This chapter assumes you can already export JPEG, PNG, WebP, AVIF, and SVG files and set quality values. It also assumes you know what srcset and sizes do. Here you will learn to decide how many bytes an image may cost, check the result against that limit, and recognize the mistakes that make pages slow.
Why a budget helps
A file-size budget is a maximum number of bytes that an image, or all the images on a page, may use. You set it before you export. Without one, "looks good" is the only test, and almost any image looks good at 2 MB.
Bytes matter because images are usually the largest part of a page. A phone on a mobile connection may receive only a few hundred kilobytes per second at first. A heavy hero image delays everything the visitor sees.
Three browser measurements show where images hurt:
- Largest Contentful Paint (LCP) is the time until the biggest visible element finishes drawing. On many pages that element is an image, so its size and loading order directly affect LCP. Google's published guidance treats 2.5 seconds or less as good.
- Cumulative Layout Shift (CLS) measures how much content jumps around while the page loads. An image without
widthandheightpushes text down when it arrives. A score of 0.1 or less is considered good. - Total page weight is the sum of all downloaded bytes. It matters most for visitors on slow or metered connections.
Your export choices control the first and third directly. They affect the second through the dimensions you hand over.
Starting numbers
The numbers below are starting points. Adjust them with your developers, and with analytics about your audience's devices and connections.
| Image role | Typical displayed width | Suggested budget per file |
|---|---|---|
| Icon or logo (SVG) | 16–200 px | 1–5 KB |
| Thumbnail or card image | 300–400 px | 20–40 KB |
| Content photo | 600–800 px | 60–120 KB |
| Full-width hero | 1200–1600 px | 150–250 KB |
| Page total (images only) | not applicable | 500 KB–1 MB |
A budget applies to the file the browser actually downloads. With srcset, a phone downloads the 400-pixel file, so that file needs to meet the small budget, not only the 1600-pixel one.
How a budget changes decisions
When a file exceeds its budget, work through the levers in order of cost to visual quality:
- Check the dimensions. An image exported at 3000 pixels wide but displayed at 800 pixels wastes most of its bytes. Halving both dimensions cuts the pixel count to a quarter.
- Check the format. A photograph saved as PNG is often several times larger than the same photograph as JPEG or WebP. A flat illustration saved as JPEG is often larger and blurrier than a PNG or SVG.
- Lower the quality setting. Step down in increments of 5 and compare the result at the displayed size.
- Try a newer format. WebP or AVIF often saves 20–50% at similar quality, depending on the image. Keep a JPEG fallback.
- Change the image. Crop tighter, simplify the background, or reduce fine texture such as noise and grain. Noise is expensive to compress.
Only after these steps should you accept a higher budget for that image.
Measuring the result
Check file sizes at three levels.
Per file. Look at the exported file in your file manager, or list sizes in a terminal:
ls -lh export/*.webpPer page. Open the page in a browser, open the developer tools, and choose the Network panel. Filter by images, reload with the cache disabled, and read the transferred size for each request. Note that "transferred" is the compressed size sent over the network, and "resource" is the size after decoding. For images these are nearly the same, because JPEG, WebP, and AVIF are already compressed.
Per scenario. Throttle the connection in the Network panel (for example to a "Fast 4G" or "Slow 4G" preset) and watch when the main image appears. Test at a phone-sized viewport and again at a desktop size, because srcset selects different files for each.
You can also script a check that fails when any exported file passes its limit. This example uses Python and needs no extra packages:
from pathlib import Path
BUDGET_KB = {"hero": 250, "card": 40, "icon": 5}
def role_of(name: str) -> str:
for role in BUDGET_KB:
if name.startswith(role):
return role
return "card"
over = []
for path in sorted(Path("export").glob("*.*")):
size_kb = path.stat().st_size / 1024
limit = BUDGET_KB[role_of(path.name)]
status = "OK " if size_kb <= limit else "OVER"
print(f"{status} {path.name}: {size_kb:.0f} KB (limit {limit} KB)")
if size_kb > limit:
over.append(path.name)
raise SystemExit(1 if over else 0)The script takes the budget role from the file-name prefix, so it depends on the naming convention you will set up in the handoff chapter. If the export folder does not exist, the loop finds no files and the script exits with 0, so create the folder first.
Common mistakes
- Budgeting only the largest file. The 400-pixel variant may be the one most visitors receive. Check every
srcsetcandidate. - Judging at the wrong zoom level. An image that looks soft at 200% zoom in your design tool may look fine at its displayed size. Compare at the size users see, and on a 2x screen if you export 2x files.
- Ignoring images that load late. Images far down the page do not affect LCP, but they still add to page weight. They are good candidates for the HTML attribute
loading="lazy", which defers the download until the visitor scrolls near them. - Lazy-loading the hero. The main above-the-fold image should load immediately. Lazy-loading it delays LCP. Your developer may add
fetchpriority="high"to it so the browser fetches it early. - Omitting
widthandheight. Without them, the browser cannot reserve space and the page shifts as images arrive. - Adding sizes without removing old ones. When a redesign adds new image variants, old unused files stay on the server. They cost nothing for visitors but make audits confusing.
- Treating a lower score as the goal. A budget is a limit, not a target. An image that is 40 KB under budget and looks sharp is fine. An image forced under budget with visible banding or blocky artifacts is not.
Where the budget fits in the workflow
The budget links the earlier decisions together. Format and quality settings decide how many bytes each file costs. Responsive images decide which file each device downloads. The budget checks both against a number agreed in advance. The next chapter turns this into a repeatable export workflow with tools.
Exercise
A designer exports a 1600-pixel-wide hero photo as a 420 KB JPEG at quality 85. Its displayed width is 800 CSS pixels, and the budget is 250 KB for the largest file. List the steps you would take, in order, and explain why you would not start by lowering the quality.
Show answer
First check the dimensions. A 1600-pixel file is correct for a 2x screen at 800 CSS pixels, so keep it as the 2x candidate, but also export an 800-pixel file for 1x screens and a smaller one (about 400 pixels) for phones, and serve them through srcset and sizes. Then re-check the 1600-pixel file's format and quality. Try quality 75–80 and compare at the displayed size. Then add WebP or AVIF versions with the JPEG as fallback, which often saves 20–50%. If it is still over 250 KB, simplify the image by cropping or reducing noise. Quality comes later because it is the lever that most visibly harms the image, and dimension and format changes often give large savings with no visible loss.
Exercise
A page's hero image loads in 4 seconds on a throttled Slow 4G connection, and the text shifts down when the image appears. Name two causes related to image export and delivery, and the fix for each.
Show answer
The first cause is a file that is too large for the connection, so reduce its dimensions, quality, or format size, and make sure the browser downloads a smaller srcset candidate on a phone. The second cause is missing width and height attributes, which stops the browser reserving space. Add width and height matching the image's aspect ratio, so the layout does not shift when the image arrives.