We cut one hero image in half and the first screen got faster than it had after a month of JavaScript cleanup. Nothing about the code changed. The thing making people wait wasn't our logic — it was a PNG the designer exported at three times the size the phone could ever display.

We were slow to notice this: on most mini-program screens, images are the heaviest thing on the page, and they're the last thing anyone profiles. We spent weeks tuning render paths and roughly no time asking whether a 2x asset was being decoded on a 1x screen. Once we did, the wins were embarrassingly cheap.

Where the bytes actually go

Format is the first cut. For the same photo, WebP is usually much smaller than PNG or JPEG, and AVIF smaller still; but not every host runtime can decode them, so you need a fallback. Our rule now is boring: modern format first, with an old format anyone can open sitting right next to it. Don't assume one format covers every host. It sounds tidy right up until you ship it.

The second cut is serving the right size. Decoding an asset prepared for a 3x screen on a small one is the most common and most pointless waste there is. A srcset-style set of variants, generated at build time, lets the device take only the file it needs. The third cut is lazy loading: images below the fold get fetched when they're near, so first paint decodes less — but the placeholder has to hold the space, or the layout jump annoys people more than the wait did.

Weak networks need their own plan. While the real image is in flight, a blurred placeholder or a flat colour block makes the screen look alive instead of empty; if it never arrives, don't wait forever, serve something usable. A CDN handles resizing and format negotiation at the edge, saving origin and transfer, at the price of putting that logic on your critical path.

TechniqueWhat it savesWhat it addsWhen it isn't worth it
WebP instead of PNG/JPEGA large slice of transfer bytes on photosAn older host runtime may not decode it; keep a fallbackA tiny icon or a one-colour shape
AVIF for hero artEven smaller files at the same visual qualitySlower encode, spottier support, another build variantWhen your pipeline can't afford a second format
Size variants for one imageNo more decoding a 3x asset on a small screenSeveral files per image and a build step to produce themA static asset that only ever renders at one size
Lazy loading below the foldFewer bytes and fewer decodes at first paintPlaceholder logic, and a risk of layout shiftAbove-the-fold content, where it only delays the obvious
CDN with device-aware transformsResizing and format negotiation at the edgeA bill, cache rules, and a vendor in your critical pathLow-traffic internal screens where a local file is fine
Blur placeholder on weak networksA screen that looks alive before the real image landsExtra markup and a low-quality asset to maintainWhen the image is tiny and arrives instantly anyway

The parts that bite back

Compatibility is the annoying one. AVIF looks best on paper, but the moment an older host runtime can't open it you need a separate variant and a way to decide which to serve. Every extra format is another build branch, another cache key, and another way for production to produce a this-user-sees-a-blank-image report. We ended up keeping AVIF for the hero and WebP with a fallback for everything else — not because AVIF is bad, but because the gain doesn't pay for that complexity.

Build complexity is the second cost. Generating several sizes sounds like a few lines of config, but in practice you're now naming derived assets, cleaning them up, and watching artefact size in CI. Design fidelity pushes back too: compress harder and gradients and fine text blur first, and the person frowning in review is the designer. We argued about it and settled on higher quality for the hero, harder compression on thumbnails, rather than measuring every image with the same ruler.

CDN cost isn't something to gloss over either. Edge transforms are billed per request, and when cache hit rate slips, the invoice and the first screen get worse together; it's also a third party on your critical path, so when it sneezes you get a blank page. That's why low-traffic internal screens just use a local file. And one that won't be popular: a CDN isn't the end of the story. It only moves the bytes somewhere else. The image still has to be small.

Start with the one image that matters

So now every screen starts with one question: which single image is the person waiting for? We export that one at the size it'll actually be displayed, give it a modern format with a fallback, and a placeholder that holds the layout. Everything below the fold can wait.

The rest of the techniques are optional. That one isn't. If you only have an afternoon, spend it on the hero asset and the cold-start request that fetches it — that's where the weight is, and no amount of code splitting will move it.

Sources