Bitpath

Lesson 1 · Unit 02

Fewer bytes

Compress text, right-size images, skip what is off screen

13 exercisesabout 3 min

What you practise

  • Compression, minifying, image formats and dimensions, responsive images with srcset, lazy loading

Try a question from this lesson

Pick one

A photo is 2000 × 1500 pixels. The page shows it in a box 400 × 300 CSS pixels on an ordinary screen. How much of the download is never seen?

Hint

Compare pixel counts, not widths: both sides are too long.

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Three ways to send less

Minify: remove spaces, comments and long local names from code. It runs the same and is smaller.

Compress: the server packs text responses with gzip or Brotli and the browser unpacks them. The browser says which methods it knows, the server says which one it used.

Right-size images: no more pixels than the screen will show, in a format made for the content.

JavaScript
function area(width, height) {
  // rectangle only
  return width * height;
}
// the same function after minifying:
function areaMin(w,h){return w*h}

Concept

One image, several widths

srcset lists the same picture in several files and gives each one's width in pixels (800w). sizes says how wide the image will be drawn, here the full viewport width.

The browser multiplies the drawn width by the screen's pixel density and picks the smallest file that covers it. A small phone gets a small file, a sharp wide screen a large one, from the same HTML.

HTML
<img src="lamp-800.jpg"
     srcset="lamp-400.jpg 400w,
             lamp-800.jpg 800w,
             lamp-1600.jpg 1600w"
     sizes="100vw" alt="Lamp">

10 more exercises in the app

  • 3× multiple choice
  • 2× fill the blanks
  • 2× type the answer
  • 2× true or false
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy