← Lessons

quiz vs the machine

Gold1440

Networking

The Prefetch and Preconnect

Doing network work early so it is ready when needed.

5 min read · core · beat Gold to climb

Working Ahead of Need

Latency hurts most when work starts only at the moment of need. Prefetch and preconnect are hints that let the client start network work early so a future resource is ready or faster to fetch.

The Family of Hints

These hints differ in how much they do ahead of time.

  • Preconnect opens the connection early, paying the handshake before the resource is requested.
  • Prefetch fetches a resource the next page is likely to need and stores it in the cache.
  • Preload fetches a resource the current page needs soon, raising its priority.

Each one moves a cost earlier so the user does not wait for it later.

The Cost of Guessing

These hints are speculative. If the prediction is wrong, the client spends bandwidth and connections on resources it never uses. On metered or busy links that waste can hurt, so hints should target high confidence predictions rather than everything.

Key idea

Prefetch and preconnect move network work earlier so future resources are ready or faster, but because they are speculative they should target high confidence predictions to avoid wasting bandwidth.

Check yourself

Answer to earn rating on the learn ladder.

1. What does preconnect do ahead of time?

2. Why should these hints target high confidence predictions?