Mini lesson · English

How to make website images load faster

Resize the supplied image with the ready tool, have an assistant connect the smaller files and verify clarity and real downloads.

Start the interactive lessonRead the lesson below

Who is this for?

People who want lighter website images without blurry or distorted results. The image and export tool are supplied; a coding assistant can connect the files for you.

Before you start

A browser, the supplied workshop and a coding assistant for the page edit. No personal photo or existing website is needed. Use the supplied measurement sheet to keep the comparison fair. Worked answers are illustrative examples, not completed tests on your account. Replace their sample observations with your own results, or identify the step that is still blocked.

Estimated time: 20–32 min

Estimates for the supplied starter files with prerequisite accounts and tools ready. Setup, deployment queues and delivery/DNS waits take additional time. Results depend on image content, viewport, pixel density and caching. File-size reduction is not automatically an equal reduction in total page load time.

What you will learn

  • Export two useful sizes from a supplied image.
  • Connect them without distorting the picture.
  • Check the file actually loaded and compare like-for-like conditions.

Workshop files

Step 1

Inspect the supplied before page

A small picture on screen can still download a large file.

Open before/index.html and look at the supplied picture. Use measurements.txt with your assistant to record the original file and its size. Keep the page’s visible purpose as your comparison.

Separate displayed size from downloaded file size. A page can shrink a large image visually without reducing what the visitor downloads.

A concrete example

The supplied page references photo-full.webp even when the picture looks small on screen. Compare the file information or browser resource entry, not the apparent width of the picture.

Use the supplied original image and export tool. Help connect the 480px and 960px exports to the after page while preserving aspect ratio and alternative text. Keep the visible layout comparable to before. Show me how to identify the actual downloaded image and compare bytes under the same cache conditions. Handle the page code for me; explain what I need to observe.

Files for this step

before/photo-full.webp
before/photo-full.webpDownload this file

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Measure what the browser downloads

A small display does not necessarily mean a small image request.

Open the before page through a local server. In developer tools, inspect the image request at a narrow viewport and record its URL and transferred bytes. Keep the cache setting consistent when comparing versions.

CSS can display a large original at a small width while the browser still downloads the original bytes. Changing the displayed width alone does not create a smaller file.

Worked example

The before page requests photo-full.webp even when its displayed width is only a few hundred pixels. Record this observation before trying the after page.

Extra implementation exercise

You set an image’s CSS width to 300px. Does that prove the browser downloaded a 300px file?

Show a worked solution

No. Inspect the selected resource. CSS sizing does not by itself change the image file at that URL.

  • Separates displayed size from resource size.
  • Checks the requested URL and actual bytes.

Step 2

Export the supplied image

Use the ready tool rather than finding your own photo.

Open tools/export.html from the lesson and choose the supplied image. Export one 480-pixel and one 960-pixel version. Keep the tool’s actual file extension, including a PNG fallback if used.

Open the exported images and compare the same subject. Check that the shape is preserved and detail is sufficient at the intended display size.

A concrete example

Open the two outputs, not just their download names. The check is “480 pixels wide, same proportions, useful detail,” not merely “a file called photo-480 exists.”

Files for this step

before/photo-full.webp
before/photo-full.webpDownload this file

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Create useful image sizes

Export sizes that match the places where your image will actually appear.

The supplied after folder includes 480px, 960px and full-width versions of the same illustration. Compare their actual file sizes and look for lost detail at the intended display size.

Open tools/export.html and choose Use supplied image to load before/photo-full.webp. Export at 480px, then 960px. The tool runs in your browser and downloads the results; it does not upload the image. Keep the supplied original for further exports. If the download ends in .png, your browser used PNG. Keep that extension and update the HTML to the actual downloaded filenames; do not rename PNG bytes to .webp.

Worked example

A 960px resource can be appropriate for an image displayed near 480 CSS pixels on a 2× screen. That is a starting estimate, not a universal rule for every layout.

Extra implementation exercise

Why might a high-density phone choose the 960px image rather than the 480px image?

Show a worked solution

Its screen may use more than one device pixel for each CSS pixel. Compare sharpness and transferred bytes under the same device conditions.

  • Recognizes that device pixel ratio affects needed pixels.
  • Evaluates sharpness at the actual displayed size.

Step 3

Connect the exported files

Give the assistant the assets and a visible acceptance check.

Ask your assistant to connect the two exports in after/index.html. Tell it how wide the image appears in the page and ask it to preserve the layout and useful image description.

Open a phone and wide view. With the assistant’s help, inspect which image the browser actually chose rather than assuming it used the smaller one.

A concrete example

At about 390 pixels the image occupies less space than it does on desktop, but a dense screen may still need the larger source. Have the assistant show the browser’s actual selected resource for your current view.

MDN: responsive images

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Tell the browser about the alternatives

srcset lists available resources; sizes describes the image’s layout width.

Read the image element in after/index.html. Each width descriptor states the actual pixel width of its file. The sizes expression approximates this page’s content width, not the raw screen width.

Keep width and height attributes to reserve a matching aspect ratio. The CSS remains flexible. An accurate alt description serves people who cannot see the image; it is not a place for a list of search keywords.

The image element's width/height attributes describe its aspect ratio and reserve layout space. They do not claim that every srcset file is 1672px wide. The 480w and 960w descriptors must match those files' actual pixel widths; device pixel ratio and the sizes layout estimate help the browser choose among them.

For this supplied layout, main has 28px padding on each side, so 56px is subtracted on narrow screens. Its 850px maximum outer width minus that padding gives the 794px content estimate. Calculate these values from your own CSS if you change the layout.

Worked example

The full source is available in the after file. A srcset descriptor that claims 960w for a 480px image would misdescribe the resource.

<img src="photo-960.webp"
 srcset="photo-480.webp 480w, photo-960.webp 960w"
 sizes="(max-width:700px) calc(100vw - 56px), 794px"
 width="1672" height="941" alt="Two people building a model house">

MDN: responsive images

Extra implementation exercise

What is wrong if sizes says 100vw but the image sits inside a much narrower content column?

Show a worked solution

The browser may select a larger resource than the layout needs. Describe the real image width and inspect currentSrc and the network request again.

  • Identifies inaccurate layout information.
  • Adjusts sizes to the actual column and retests resource selection.

Step 4

Compare under the same conditions

Do not compare a fresh download with a cached one.

Use the same page, view and cache conditions for before and after. Let the assistant guide the browser measurement steps; record file bytes separately from timing.

A smaller measured download can be evidence for this image change. Timing can vary, so do not call one inconsistent run a proven site-wide speedup.

A concrete example

Do not compare a fresh original download with an after image already in cache. Record the selected file and cache condition on both sides before interpreting the numbers.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Compare under the same conditions

Verify the selected image, file size and appearance together.

Compare the before and after pages with the same viewport, device pixel ratio and cache policy. Inspect currentSrc or the Network panel to learn which candidate the browser selected.

Resize the viewport and repeat. A browser may retain an already downloaded larger resource; start a fresh test when needed. Judge the image at its displayed size and record artifacts or blur, not just a smaller byte count.

Worked example

A sound record says “390px, 1×, cache disabled, resource X, Y bytes”. A single load-time number from different network conditions is not a controlled comparison.

Extra implementation exercise

Before was tested with a cold cache and after with a warm cache. Is the timing difference reliable evidence for your change?

Show a worked solution

No. Repeat with equivalent cache and network conditions. Compare actual resource selection and bytes as well as timing.

  • Identifies the changed cache condition.
  • Repeats the measurement with a consistent setup.

Step 5

Finish the image improvement

Show a lighter download that still looks right.

Complete the 480/960 exports and connection, then repeat the file-choice and appearance checks. Keep the supplied original available for comparison and save the updated page.

Check clarity, aspect ratio and actual resource selection. Record what was observed; the reference files show a comparison, not your browser’s result.

A concrete example

A complete result includes both sides: which smaller resource the browser loaded and whether the picture still does its job. A small file that is stretched or unreadable is not a finished improvement.

Files for this step

before/photo-full.webp
before/photo-full.webpDownload this file

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Your assignment: optimize the supplied website image

Preserve useful visual detail while delivering an appropriate resource.

Start with before/photo-full.webp, the illustration supplied with this lesson. Use tools/export.html to create 480px and 960px versions. Save them in after/ and update after/index.html; keep the image content, layout and alt text unchanged.

Record the before/after request and a visual check. If the browser chooses a larger candidate for a high-density screen, explain that result instead of forcing the smallest file.

Worked example

Your report should name the image, conditions, selected resource and quality trade-off. Do not replace a meaningful photo with an unrelated tiny graphic just to improve the measurement.

The full approach is in reference/assignment-walkthrough.txt. Use the supplied before/after pages and fill measurements.txt with your observed results. You do not need to bring an image or build a website first.

Extra implementation exercise

Use before/photo-full.webp to create 480px and 960px images, connect them in after/index.html and demonstrate which resource the browser requests.

Show a worked solution

At a 390px viewport and deviceScaleFactor=1, open a fresh before page with consistent cache conditions and record currentSrc and actual image bytes. Do not infer the downloaded width from the CSS box.

In the after page the supplied 480w candidate should be a suitable small-screen option, but record the browser's actual choice. At higher pixel density, the 960w candidate may be reasonable. The width/height HTML attributes preserve aspect ratio; each srcset descriptor describes its own file.

Load before/photo-full.webp in tools/export.html, export at 480px and 960px, and save the files in after/. Set each srcset width descriptor to its actual exported width. Repeat the same viewport, pixel density and cache conditions, and record currentSrc, resource dimensions, bytes and visible detail in measurements.txt. Use observed numbers, not invented savings.

  • Descriptors match actual widths and the layout remains stable.
  • A controlled comparison shows the selected resources and acceptable visual quality.

Was this lesson useful?

Leave a like, or share it with someone who could use it.

Continue learning

Explore the other lessons