Nextjs Fundamentals · Data Fetching

Preloading data

avoiding request waterfalls

Preloading data

A request waterfall happens when a component's data request cannot start until earlier, unrelated work has finished. If a child renders only after a slow check completes, its own fetch begins late — even though its inputs were known all along.

Preloading starts that request early, so it runs in parallel with the blocking work. Export a preload helper next to the component that consumes the data, and call the fetching function without await:

export const preload = (id: string) => {
  void getItem(id);
};

Then call it before the slow work, and render the component afterwards:

export default async function Page({ params }) {
  const { id } = await params;
  preload(id);
  const isAvailable = await checkIsAvailable(id);
  return isAvailable ? <Item id={id} /> : null;
}

The item request continues while checkIsAvailable() runs. When <Item> finally renders and calls getItem(id) again, it must reuse the request that preloading started. That deduplication is what makes the pattern work: identical fetch calls are memoised automatically, and non-fetch access must be wrapped in React.cache (or, with Cache Components, a 'use cache' function).

Keep the preload helper beside the component so the dependency stays easy to find. The goal is simple: start the fetch as early as the inputs are known.

You are about to answer a short quiz on avoiding request waterfalls.

  1. A request waterfall happens when a request cannot start until earlier work finishes.
  2. A preload helper starts a request early by calling the fetching function without ___.
  3. For the preload pattern to work, the later call must reuse the request the preload started.
  4. For non-fetch data access, wrap the fetching function in ___ so preloaded and later calls deduplicate.
  5. Preloading is meant to make a request start later, closer to when the component renders.