Sub topic 12
Keeping pages light on mobile connections
This chapter assumes you can build a single-column layout, use srcset and sizes, and read the Network panel in browser developer tools. Here you will set a limit on page weight and use it to decide what ships to small screens.
Why weight matters more on mobile
A phone often has a slow or unstable connection, a less powerful processor, and a data plan that charges for every megabyte. A page that feels fine on office broadband can take many seconds to show anything on a congested 4G link. Every byte you send must be downloaded, and scripts must also be parsed and run. Mobile-first design pushes you to ask early what the smallest screen really needs.
Set a performance budget
A performance budget is a limit you agree on before building, then check while building. Without one, pages grow a little with each added feature until they are slow.
| Measure | Example budget |
|---|---|
| Total transfer size on first load | 500 KB |
| JavaScript (compressed) | 100 KB |
| Images above the fold | 150 KB |
| Largest Contentful Paint (when the main content appears) | 2.5 s on a throttled mid-range phone |
These numbers are examples. Pick values from your audience's real devices and networks, and write them down so the team can check against them.
Where the weight comes from
Check the Network panel and sort by size. On most pages the biggest items are, in order, images, JavaScript, web fonts, and CSS. Work on the largest first.
Images
You already know how to serve the right size with srcset. Two more rules affect weight. Use loading="lazy" only for images below the fold. Never lazy-load the main image at the top, because that delays the most visible content. Also prefer modern formats such as WebP or AVIF where your audience's browsers support them, and compress every file.
Fonts
Each font file is another request. Limit yourself to one or two families and a few weights. Use font-display: swap so text appears in a fallback font while the custom font downloads.
@font-face {
font-family: "Body Sans";
src: url("/fonts/body-sans.woff2") format("woff2");
font-weight: 400;
font-display: swap;
}
body {
font-family: "Body Sans", system-ui, sans-serif;
}A system font stack such as system-ui, sans-serif costs nothing to download and is a legitimate choice for small budgets.
JavaScript
Scripts block rendering unless you tell the browser otherwise. Add defer so the script downloads while the page is parsed and runs afterwards.
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Support team</title>
<link rel="stylesheet" href="styles.css">
<script src="app.js" defer></script>
</head>Before adding a library, ask whether CSS or a native element can do the job. The details element from the progressive disclosure chapter needs no script at all.
Mobile-first CSS helps the budget
Because your base rules target small screens, a phone parses only simple single-column styles plus the media queries that apply to it. Desktop-first stylesheets often ship complex layouts that small screens then undo. Keep the base CSS small and put larger-screen rules inside min-width queries.
Measure on realistic conditions
Your laptop on fast Wi-Fi hides problems. In developer tools, set network throttling to a slow 4G profile, enable CPU throttling, and disable the cache. Then reload and record total transfer size and load time. Run Lighthouse for a repeatable report. Confirm the results on a real mid-range phone when you can.
Common errors
- Lazy-loading the hero image, which delays the most important content.
- Loading four font weights when the design uses two.
- Testing only on an unthrottled desktop connection.
- Adding a large library for one small feature.
Exercise
Your page's Network panel shows 1.4 MB transferred on a throttled connection. The budget is 500 KB. Name the first thing you check and one action you might take.
Show answer
Sort requests by size and look at the largest items, which are usually images. Actions include resizing or compressing the images, serving them with srcset, converting them to WebP or AVIF, or lazy-loading those below the fold. After the change, measure again under the same throttling.