Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OS 4.3 (6 of 12): Choosing graphics, audio and video

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Why is the page so slow?

You open a shop page on your phone. You wait. And wait. The page is slow.

The reason is often one huge photo. It is 12 MB, and the screen shows it very small.

Developers choose pictures, sounds and videos with care. This lesson shows you how.

Key words

WordWhat it meansExample
AssetA file your software uses.logo.png
File typeThe format of a file. The ending of its name often shows it..jpg, .mp3
File sizeHow much space a file takes.4 MB
CompressionMaking a file smaller.
LossyCompression that removes detail for good.JPEG, MP3
LosslessCompression that keeps every detail.PNG, ZIP
StreamingPlaying a sound or video while it downloads.
MetadataFacts about a file.date, author, size
BandwidthHow much data a connection can carry each second.10 MB per second

The cells students fill in are left blank in this preview.

Small and large: KB and MB

UnitAbout how bigExample
1 KB (kilobyte)A short text fileA page of plain text
1 MB (megabyte)1,000 KBOne web photo, or a minute of music
1 GB (gigabyte)1,000 MBA film, or a game update

The cells students fill in are left blank in this preview.

Quick check: compression

Have a go

Quick check: compression

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Common file types

AssetTypeGood forWatch out
GraphicJPEG (.jpg)Photos. Small files, lossyBlurry edges on text and logos
GraphicPNG (.png)Logos, icons, clear edges. LosslessLarge files for photos
GraphicSVG (.svg)Shapes and logos that scale to any sizeNot for photos
AudioMP3 (.mp3)Music. Small, lossySome detail is lost
AudioWAV (.wav)Short sound effects, full qualityVery large files
VideoMP4 (.mp4)Almost every device plays itNeeds careful encoding (see below)
CodeJavaScript library (.js)Ready-made code that adds a featureEvery library adds KB and has rules for how you may use it

The cells students fill in are left blank in this preview.

Match the job to the type

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Audio and video: stream or not?

A long video is too big to download first. So you stream it. The player shows the start while the rest still arrives.

To encode means to change a recording into a file format and a size that suits the device. You encode a video once, then stream it.

You can also embed a video. This means you put a player on your page that plays a video stored somewhere else, such as YouTube.

Worked example: size and time

QuestionStepAnswer
50 photos, 4 MB each. How much space?4 MB times 50 = 200 MB200 MB
A 100 MB file on a connection of 10 MB per second. How long?100 MB divided by 10 MB per second10 seconds
The same file on 5 MB per second?100 divided by 520 seconds
Two files, 3 MB and 7 MB. Total?3 + 710 MB

The cells students fill in are left blank in this preview.

Ask six questions about every asset

Important

What quality do users need? How much bandwidth do they have? How much storage is there? Which device will show it? Which file type does that device play? Is there metadata to keep, such as the author and who owns it?

Work out the sums in Python

Code: python
photo_mb = 4
count = 50
print("Space needed:", photo_mb * count, "MB")

file_mb = 100
speed = 10
print("Seconds:", file_mb / speed)

# Change the speed to 5 and run again.

Make a free account to save your work and track your progress.

Check a page against its budget

A web team has a budget for each page. Write four small functions. The first adds up the sizes of the assets in KB. The second works out the download time. The third says if the page is inside the budget. The fourth finds the largest asset, the first one to shrink. Press Run Tests.

Code: python
def page_weight(assets):
    # assets is a list of pairs: (name, size in KB), like [("logo.png", 20), ("photo.jpg", 400)].
    # Give back the total size in KB.
    return None


def load_seconds(total_kb, speed_kb_per_second):
    # Seconds to download total_kb at the given speed. 1000 KB at 500 KB per second is 2 seconds.
    return None


def fits_budget(assets, limit_kb):
    # True if the page weight is the limit or less. Otherwise False.
    return None


def biggest_asset(assets):
    # Give back the NAME of the largest asset. An empty list gives back None.
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

Sizes and sums

Have a go

Sizes and sums

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.