Sub topic 16
File-size budgets and page performance
This chapter assumes you know how to pick a format, export at the right dimensions, and set compression quality. Here you will learn how to decide whether the resulting files are small enough.
Why images need a budget
Images are usually the largest part of a page's download. A slow page loses visitors, and the biggest image on screen often decides when the page looks loaded. Browsers report this as Largest Contentful Paint (LCP), the time until the largest visible element is drawn. A hero photo is often that element.
A file-size budget is a maximum size you agree on before exporting. It turns "make it light" into a number you can check.
Setting a budget
Start from the page, then work down to single images.
- Pick a total weight for all images on the first screen. Many teams choose 300 to 500 KB.
- Split that total across the images. A hero image gets the largest share. Thumbnails and icons get small ones.
- Write the limit next to each image in the design file.
The numbers below are example starting points. Adjust them to your audience and network conditions.
| Image type | Example budget |
|---|---|
| Hero photo | 150 KB or less |
| Card thumbnail | 30 KB or less |
| Logo or icon (SVG) | 5 KB or less |
| Whole page, all images | 500 KB or less |
Spend the budget where it shows
A budget is not an even split. Spend bytes on the image that matters most and cut them from images the visitor barely notices.
- Lower quality on large, soft photos first. Compression artifacts are hard to see there.
- Use the smallest dimensions that still look sharp at the displayed size.
- Prefer SVG for icons and logos, since they are usually tiny.
- Load images below the first screen later. Add
loading="lazy"to them. Do not add it to the hero image, because that delays the image the visitor sees first.
<img
src="card-400.webp"
width="400"
height="300"
loading="lazy"
alt="Product card photo">Keeping width and height on every image lets the browser reserve space. The layout then does not jump when the file arrives.
Checking against the budget
When an image is over budget, change one thing at a time. Reduce dimensions first, because pixel count affects file size the most. Then lower quality. Then try a more efficient format such as WebP or AVIF.
Common mistakes
- Judging only the file size and never looking at the image.
- Exporting 2x files for every image, including ones that do not need them.
- Setting a budget after the images are finished, when cutting means redoing the work.
Exercise
Your hero image is 420 KB against a 150 KB budget, and it is exported at 3200 pixels wide for a slot that displays at 800 CSS pixels. What do you change first, and why?
Show answer
Reduce the dimensions first. At 2x, 1600 pixels wide is enough for an 800 pixel slot, and cutting the pixel count shrinks the file far more than a small quality change. Then lower quality, and only then try WebP or AVIF if the file is still over budget.