🎓 A1Learner
🔍
0 of 50 lessons completed

Next.js loading.tsx

loading.tsx is a skeleton page. It shows while the real page is still loading.

The skeleton file

The file holds one heading. It is the whole placeholder.

export default function Loading() {
  return <h1>Loading books…</h1>;
}

The streamed page holds both texts

The check saves the streamed page, then reads it twice. The skeleton text and the content text are both there.

curl -s -N http://localhost:3103/books -o /tmp/books-stream.html
grep -o "Loading books…" /tmp/books-stream.html
grep -o "Books on the shelf" /tmp/books-stream.html

Example

curl -s -o /dev/null -w "first-byte:%{time_starttransfer}s total:%{time_total}s status:%{http_code}\n" http://localhost:3103/books

Key points

  • Skeleton: a simple placeholder that shows while the real content loads
  • loading.tsx sits next to page.tsx. It wraps that page only.
  • The books page waits 2 seconds. The skeleton shows first, then the books appear.
  • The first byte arrived after 1.97 seconds. The whole page took 3.68 seconds.
  • The streamed page holds both texts: "Loading books…" and "Books on the shelf".
  • Streaming: the server sends the skeleton first, then the content when it is ready.

In this example, the check asks the dev server on port 3103 for /books. The first byte arrived after 1.97 seconds, and the whole page took 3.68 seconds. The status is 200, so the page worked. The skeleton filled the wait, and the books followed it in the same streamed page.

Note

The skeleton is not the page. It is a stand-in, so keep it short and simple.

Try it Yourself

Edit the code, then press Run.

Running is simulated · TypeScript Playground

Exercise

What does loading.tsx show?