html · level 3 · unit 2 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
fetches a file before the browser finds it.
A website's files live on a server, a computer that sends them to any browser that asks. Each ask is a . The browser reads your HTML from the top and sends a request for each file it finds.
Some files are found late. A , the file of design rules you will meet in CSS, might ask for a big background picture. The browser only learns about it after the stylesheet has arrived.
Preload jumps the queue: <link rel="preload"> in the head names the file, and as says what kind it is, like as="image". Preload only what the first screen needs, or everything else slows down.
<!doctype html>
<html lang="en">
<head>
<title>Pip's Plants</title>
<link rel="preload" href="tree.svg" as="image">
</head>
<body>
<h1>Pip's Plants</h1>
<p>The tree behind this heading comes from our stylesheet.</p>
</body>
</html> Press show my page to see it here.
<link> is an empty element that lives in the head. Its rel says how the file relates to your page.
guess first
Which file does the browser ask for first?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<head>
<title>Bake Street</title>
<link rel="preload" href="cake.svg" as="image">
</head>
<body>
<img src="logo.svg" alt="Bake Street Bakery" width="200" height="200">
<p>Fresh bread from 7am.</p>
</body>
your turn
Your turn. Preload the background.
The stylesheet uses ball.svg as a big background picture. Preload it: fill rel and as on line 5.
Press show my page to see it here.
- the link preloads a filenot checked yet
- it says the file is an imagenot checked yet
fix it
The preload is ignored. Can you fix it?
Press show my page to see it here.
- the preload says what kind of filenot checked yet
- it still preloads
dog.svgnot checked yet
- Browsers will not preload a file unless they know what kind of file it is.
- A preload needs an
asattribute. This file is a picture. - Add
as="image"to the<link>on line 5, then press run.
nailed it
you jumped the queue. :D
- Every file a page uses is a request to a server.
<link rel="preload">fetches a file the browser would find late.- Always add
as, and preload only what matters now.
new words in your collection
- request
- stylesheet
- preload
This lesson isn’t saved. A free account remembers every lesson you finish.