FE5: Loading less, loading later

Lesson 3 of 5 ยท reading 15โ€“25 minutes; practice and project time is on the module page

Serving the right images

๐ŸŽฏYou'll be able to

Serve images at the right size and format for each screen.

๐Ÿ The everyday picture

You don't send a wedding album's poster-sized print by WhatsApp to show a friend one photo. You send a smaller copy that looks just as good on their phone.

๐Ÿ“˜What it really is

๐Ÿ“A worked example

Kirana's product photos before and after an image pipeline:

Measure Before After
Typical file 3.2 MB JPEG, 4,000 ร— 3,000 45 KB WebP at 600 px wide (90 KB at 1,200 px for sharp screens)
Listing page with 40 products 18 MB 1.9 MB
Format fallback โ€” JPEG for the rare browser without WebP

Uploads now go through a step that creates three sizes in WebP and AVIF, and the page uses srcset so phones get the smaller files.

๐ŸŒWhere it's used

๐Ÿ“Case scenario

A restaurant site's menu page takes 20 seconds to load on mobile data. Each dish photo is a 4 MB original from a professional camera. Converting to WebP at display size cuts the page from 60 MB to 2.5 MB, and the restaurant notices fewer people leaving the menu page before ordering.

๐Ÿ–ฑ๏ธTry it

Take five large photos, and for each produce a WebP at 600 px and 1,200 px wide. Use srcset and sizes on your Kirana product page, and check in the Network tab which file the browser chose on a phone-sized screen.

โš ๏ธCommon mistakes

๐Ÿ› ๏ธFor your project

The kit's product images are 1200 px JPEGs and the hero is 2400 px; Project 3's image budget is 900 KB.

โœ…Quick check

What do srcset and sizes do?

Show the answer

They let the browser pick the most suitable image file for the screen width and pixel density.

Name two image formats that are usually smaller than JPEG at similar quality.

Show the answer

WebP and AVIF.

โ† PreviousLazy loading below the fold
ProLearners Assist