Professional Business Website · Project

Professional Business Website · Phase 4 · Lesson 2 of 3

Images and Performance for Slow Connections

Resize and compress photos, add width, height and lazy loading, and measure the page weight so the site loads quickly on expensive mobile data.

What you need

A computer (Windows, macOS or Linux) with Visual Studio Code (free) and a current web browser such as Chrome or Firefox. A smartphone is used for testing. A free image editor (such as GIMP) for resizing and compressing photos.

In this lesson you will

  • Resize and compress images for the web
  • Measure and reduce total page weight

Key concepts

page weightimage compressionWebPlazy loadingwidth and heightLighthouse

The lesson

Photos straight from a phone camera are often 3–5 MB each. On a home page with five photos that is more data than many customers want to spend. Resize images to the largest size they are shown at (often about 1,200 pixels wide) and compress them; modern formats such as WebP are usually much smaller than JPEG at similar quality.

Add width and height attributes so the page does not jump while images load, and loading="lazy" to images below the first screen so they download only when needed.

Measure: the browser's Network tab shows total transferred size, and Lighthouse in Chrome scores performance. The worked example shows how much data careful images save.

Step by step

  1. Record the current page weight of the home page in the Network tab.
  2. Resize and compress every photo; save web versions in the images folder.
  3. Add width, height and lazy loading to images.
  4. Measure again and run a Lighthouse audit; record before and after.
Worked calculation

How much data the home page saves after image optimisation

Comparing the home page with original camera photos against resized, compressed images.

Home page of the fictional Amani Tailoring site with five photos (illustrative sizes; measure your own pages in the browser's Network tab)
ItemWorkingAmount
Original photos5 photos × 3.2 MB16.0 MB
Optimised photos5 photos × 180 KB (1,200 px wide, compressed)0.9 MB
HTML, CSS and JavaScriptunchanged0.06 MB
Page before → after16.06 MB → 0.96 MB≈ 94% less data

Explanation

Images are almost always the largest part of a small business page. Resizing to the displayed size and compressing them removes most of the weight with no visible loss on a phone.

A customer opening the original page five times would download about 80 MB; the optimised page needs under 5 MB.

Check your understanding

Saving = (16.06 − 0.96) ÷ 16.06 ≈ 0.94, so about 94% less data per visit.

Practice activity

Optimise every image on the site and produce a before-and-after performance record for the home page.

Expected result: A home page under about 1 MB in total, with a before-and-after record and a Lighthouse report.

Common mistakes

  • Uploading original camera photos and shrinking them only with CSS
  • Lazy-loading the main image at the top of the page, which delays it

Check your understanding

  1. Why add width and height attributes to images?

    Show answer

    So the browser reserves space and the layout does not jump while images load.

  2. What does loading="lazy" do?

    Show answer

    Delays downloading images below the visible screen until the visitor scrolls near them.

Further learning

Projects are instructor-guided: an instructor sets milestones, checks your work and gives feedback, online or in person. Self-study of the public lessons does not lead to a certificate. Enrolment and fees follow the Academy's existing policies — contact the Academy.