KodingKaro
HTML · Advanced · HTML Performance

Resource hints and preload

Resource hints can reduce delays, but they are valuable only when they help the browser fetch a resource it truly needs.

✓ What you will learn in this topic

  • Explain the purpose of Resource hints and preload in a real HTML document.
  • Choose and apply the elements shown in both examples.
  • Recognize the specific mistake described in this lesson.

Concept explanation

Preload tells the browser to fetch a known critical resource early and requires the correct as destination. Preconnect establishes an early connection to a cross-origin host that the page will definitely use soon. These hints compete for network and CPU resources, so do not add them by habit. Preload fonts with the expected type and cross-origin mode, and verify browser behavior with performance tools.

Syntax

Use rel=\"preload\" with the correct as value for a critical resource; use preconnect only for an essential origin.

Example 1: a small page

The destination, resource type, and cross-origin setting help the browser fetch the font correctly.

<link rel=\"preload\" href=\"/fonts/reading.woff2\" as=\"font\" type=\"font/woff2\" crossorigin>

Expected result: The browser can start fetching the font before CSS discovers it, if the page uses this exact resource.

Example 2: a practical page

The connection hint is useful only if the page needs that media origin immediately; the hero is preloaded only if it is the key visible image.

<link rel=\"preconnect\" href=\"https://media.example.org\" crossorigin>
<link rel=\"preload\" href=\"/images/home-hero.avif\" as=\"image\">

Expected result: Critical assets may arrive sooner, while unnecessary hints should be omitted to avoid competing downloads.

Common mistakes

Do not preload resources speculatively; an incorrect preload can compete with more important page content.

Best practices

Measure first, prioritize the actual critical resource, and use async or defer according to script dependencies.

Practice exercise

Review a page head with a font, hero image, and two scripts. Decide which resource is truly critical and justify any preload, preconnect, async, or defer hint.

Lesson summary

  • Resource hints are performance instructions; measure and prioritize only resources the page needs soon.
  • Measure first, prioritize the actual critical resource, and use async or defer according to script dependencies.

Knowledge check

What should determine whether a resource is preloaded?

Show the explanation

It should be a known critical resource needed early in rendering, not merely a file that might be used later.

Practical example

html
<link rel=\"preload\" href=\"/fonts/reading.woff2\" as=\"font\" type=\"font/woff2\" crossorigin>

Expected result:

The browser can start fetching the font before CSS discovers it, if the page uses this exact resource.

Hands-on practice task

Review a page head with a font, hero image, and two scripts. Decide which resource is truly critical and justify any preload, preconnect, async, or defer hint.

In this section

Other lessons in HTML Performance

Broaden your knowledge

Related learning topics