BeginnerLesson 8 of 306 min read

Mobile Friendliness, Page Speed and Image Size

Learn mobile-first indexing, the three Core Web Vitals and how to cut image weight, with a real measurement of file sizes across formats.

In this lesson you will

  • Explain mobile-first indexing
  • Name the Core Web Vitals
  • Cut image weight
  • Write better image HTML

About 17 minutes

The portfolio that would not load

Ken is a photographer. His portfolio page looks beautiful on his big monitor. But his sister, on a train with a phone and a patchy signal, waited so long that she gave up. Ken’s page was not broken. It was heavy: every photo was uploaded straight from the camera. Visitors leave slow pages, and search engines pay attention to how pages feel to use. This lesson covers the three linked topics of mobile friendliness, speed and images.

Mobile first

Most searches today happen on phones, and Google primarily uses the mobile version of a page to decide what to index and rank. This is usually called mobile-first indexing. In plain terms, your phone layout is the one that counts. That means text readable without zooming, buttons big enough to tap, no sideways scrolling, and the same content on mobile as on desktop. Most modern themes handle this, but they depend on one line in the page head.

<meta name="viewport" content="width=device-width, initial-scale=1">

Without it, phones may show a tiny zoomed-out desktop page. Test by opening your site on a real phone and trying to do what a visitor would do.

Speed and the three Web Vitals

Google describes page experience with measurements called Core Web Vitals. At the time of writing there are three. LCP (largest contentful paint) is how long the biggest visible item takes to appear. INP (interaction to next paint) is how quickly the page responds when someone taps or clicks. CLS (cumulative layout shift) is how much the page jumps around while loading. Google publishes target values for each, and they can change, so check the current figures on web.dev rather than trusting a number in a lesson. Free tools such as PageSpeed Insights and the Lighthouse panel in the Chrome browser measure them for your pages. Those tools run on the web, so they were not run for this lesson.

Page experience is one of many signals. A fast page with poor content will not outrank a slower, much more helpful one. But a slow page loses visitors before they read anything, so it is worth fixing, and images are usually the biggest cause.

Measure image weight

The program below makes a large test picture (2400 by 1600 pixels), saves it in several ways, and prints the file sizes. The picture is synthetic, made from colour, texture and noise, because we have no camera here. A real photo will compress by different amounts, so always test your own. The output is real, and we confirmed the sizes by also saving each file to disk and checking its size there.

import io
import numpy as np
from PIL import Image

# A SYNTHETIC test picture (colour, texture and noise).
# A real photo will compress differently, so test your own.
rng = np.random.default_rng(7)
w, h = 2400, 1600
x = np.linspace(0, 1, w)[None, :]
y = np.linspace(0, 1, h)[:, None]
pix = np.zeros((h, w, 3))
pix[..., 0] = 40 + 160 * x
pix[..., 1] = 60 + 140 * y
pix[..., 2] = 150 + 80 * np.sin(6 * x + 4 * y)
for scale in (8, 40, 200):
    tiny = rng.normal(0, 14, (h // scale + 2, w // scale + 2, 3))
    pix += np.kron(tiny, np.ones((scale, scale, 1)))[:h, :w]
pix += rng.normal(0, 9, pix.shape)
img = Image.fromarray(np.clip(pix, 0, 255).astype("uint8"))

def size_kb(image, **kw):
    buf = io.BytesIO()
    image.save(buf, **kw)
    return len(buf.getvalue()) / 1024

small = img.resize((1200, 800))
rows = [
 ("PNG, 2400 wide",          size_kb(img, format="PNG")),
 ("JPEG q95, 2400 wide",     size_kb(img, format="JPEG", quality=95)),
 ("JPEG q80, 2400 wide",     size_kb(img, format="JPEG", quality=80)),
 ("JPEG q80, 1200 wide",     size_kb(small, format="JPEG", quality=80)),
 ("WebP q80, 1200 wide",     size_kb(small, format="WEBP", quality=80)),
]
base = rows[0][1]
for name, kb in rows:
    print(f"{name}: {kb:.0f} KB ({100 * (1 - kb / base):.0f}% smaller)")
page_before = 6 * rows[0][1] / 1024
page_after = 6 * rows[3][1] / 1024
print(f"Six images on one page: {page_before:.1f} MB before, {page_after:.2f} MB after")
PNG, 2400 wide: 8147 KB (0% smaller)
JPEG q95, 2400 wide: 1984 KB (76% smaller)
JPEG q80, 2400 wide: 694 KB (91% smaller)
JPEG q80, 1200 wide: 177 KB (98% smaller)
WebP q80, 1200 wide: 98 KB (99% smaller)
Six images on one page: 47.7 MB before, 1.04 MB after

The uncompressed-style PNG is about 8.0 MB. Saved as a high-quality JPEG it drops to about 1.9 MB, and at quality 80 to about 694 KB. The biggest saving of all comes from resizing. A phone screen is a few hundred pixels wide, so sending a 2400-pixel image wastes data. At 1200 pixels wide the JPEG is only 177 KB, and the WebP version is 98 KB. Six images on one page weigh about 47.7 MB before and about 1.04 MB after.

That is the whole story of image speed: resize first, then compress, then choose a modern format. Use JPEG for photographs and PNG for sharp graphics or transparency. WebP is widely supported by browsers today and is usually smaller still, though you should check support for your audience.

HTML habits for images

<img src="candle-1200.webp" width="1200" height="800"
     alt="Lit lavender candle in a glass jar"
     loading="lazy">
  • width and height let the browser reserve space, which stops the page jumping (it helps CLS).
  • alt describes the image for screen readers and gives engines context.
  • loading=”lazy” delays images far down the page until needed. Do not lazy-load the main image at the top, because it should appear first.
  • A real file name such as lavender-candle.webp is more helpful than IMG_4471.
Shrinking in the browser

Uploading camera originals and letting the page shrink them with code. The browser still downloads the full file. Resize before you upload.

Quality still matters

Compression that is too strong makes images blurry. Look at the picture after compressing, and pick the smallest file that still looks good at the size shown on the page.

Open your three largest pages. Using your browser’s developer tools or a free page-speed checker, find the heaviest image. Resize it to the width it is actually shown at, compress it and compare the file sizes before and after.

Practice for this lesson

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

What does mobile-first indexing mean?

  1. Only phones can see your site
  2. Desktop pages are deleted
  3. Apps replace websites
  4. Google mainly uses the mobile page

Google primarily uses the mobile version of your page to index and rank it.

Which Web Vital measures page jumping?

  1. LCP
  2. CLS
  3. INP
  4. URL

Cumulative layout shift measures how much content moves while the page loads.

What is the best first step to shrink a heavy photo?

  1. Add more keywords
  2. Rename the file
  3. Make it a PNG
  4. Resize it to the displayed width

Sending far more pixels than the screen shows is the biggest waste, so resize before compressing.

Which image should NOT be lazy-loaded?

  1. The main image at the top
  2. A footer photo
  3. A photo far down
  4. A gallery thumbnail

The top image should appear first, so delaying it would slow the page.

Why were the image sizes in the demo only a guide?

  1. Python cannot save images
  2. File sizes are random
  3. The picture was synthetic
  4. WebP is not real

A made-up picture compresses differently from a real photo, so test your own images.

Summary

  • Your phone layout is the version search engines mainly use.
  • LCP, INP and CLS describe loading, response and stability.
  • Resize first, then compress, then pick a modern format.
  • Use width, height, alt and lazy loading on images.

Next lesson

Lesson 9 covers links from other sites and the most common beginner mistakes.

Questions

Is page speed a big ranking factor?

It is one of many signals and will not rescue weak content. But slow pages lose visitors quickly, so speed matters for people even when it is a small factor for ranking.

Which image format should I use?

JPEG for photos, PNG for sharp graphics or transparency, and WebP as a smaller modern option that most browsers support. Test your own images because results vary.

How do I test my page speed for free?

Use PageSpeed Insights or the Lighthouse tool built into Chrome. Test on a phone-sized setting, and repeat the test after each change to see what helped.

Progress is saved in this browser.