Next.js 15 Fullstack (App Router + Server Actions) · บทเรียน

การดึงข้อมูลแบบขนาน แบบลำดับ และแบบสตรีม

เพิ่มประสิทธิภาพการโหลดข้อมูลของตัวจัดเส้นทางแอปด้วยการดึงข้อมูลแบบขนาน ทำความเข้าใจว่าเมื่อใดจำเป็นต้องดึงข้อมูลตามลำดับ และสตรีมข้อมูลด้วย Suspense

บทเรียน 3 จาก 313 ขั้นตอน

การดึงข้อมูลแบบขนาน แบบลำดับ และแบบสตรีม เป็นบทเรียน Next.js 15 Fullstack (App Router + Server Actions) ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 3 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Next.js 15 Fullstack (App Router + Server Actions) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Next.js 15 Fullstack (App Router + Server Actions) มีบทเรียนทั้งหมด 3 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Two Fetching Shapes

Server Components can fetch data sequentially (one waits for another) or in parallel (all at once). Choosing well dramatically affects load time.

Sequential Fetching

Sometimes one request depends on another result, forcing order. This creates a waterfall and is slower.

const user = await getUser(id);
const posts = await getPosts(user.teamId); // needs user first

Parallel Fetching

Independent requests should start together. Initiate the promises, then await them with Promise.all.

const userP = getUser(id);
const postsP = getPosts(id);
const [user, posts] = await Promise.all([userP, postsP]);

Avoiding Waterfalls

An accidental waterfall happens when you await each fetch on its own line even though they are independent. Kick them off before awaiting.

Streaming with Suspense

You do not have to wait for everything. Wrap slow parts in Suspense so fast content streams to the user immediately.

import { Suspense } from "react";
<Suspense fallback={<Spinner />}>
  <SlowComponent />
</Suspense>

loading.tsx is Suspense

The special loading.tsx file is automatically a Suspense boundary for the whole route segment, giving an instant loading state.

Granular Streaming

Place multiple Suspense boundaries so each section reveals as soon as its own data is ready, instead of blocking on the slowest one.

Fetching at the Leaf

In RSC you can fetch data exactly where it is needed (in the component that uses it). React dedupes identical requests, so colocated fetches are fine.

Request Memoization

Next.js memoizes fetch calls with the same URL/options within a single render pass, so calling it in multiple components does not hit the network twice.

Preloading Data

You can start a fetch early (a preload function called before render) to overlap network time with rendering of other parts.

export function preload(id) { void getUser(id); }

Picking a Strategy

Default to parallel + colocated fetching; add Suspense boundaries around slow, independent sections; only go sequential when a real data dependency exists.

Quick Check

How do you avoid a data fetching waterfall for two independent requests?

Recap

You learned to fetch in parallel with Promise.all, avoid accidental waterfalls, and use Suspense (including loading.tsx) to stream UI progressively. Next.js memoizes fetches, so colocated leaf fetching is efficient.

เริ่มต้นได้ฟรี

เรียนรู้ TypeScript ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
22
บทเรียน
88

คำถามที่พบบ่อย

บทเรียน “การดึงข้อมูลแบบขนาน แบบลำดับ และแบบสตรีม” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การดึงข้อมูลแบบขนาน แบบลำดับ และแบบสตรีม” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Next.js 15 Fullstack (App Router + Server Actions) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Next.js 15 Fullstack (App Router + Server Actions) มีบทเรียนทั้งหมด 3 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การดึงข้อมูลแบบขนาน แบบลำดับ และแบบสตรีม”

เพิ่มประสิทธิภาพการโหลดข้อมูลของตัวจัดเส้นทางแอปด้วยการดึงข้อมูลแบบขนาน ทำความเข้าใจว่าเมื่อใดจำเป็นต้องดึงข้อมูลตามลำดับ และสตรีมข้อมูลด้วย Suspense คุณปฏิบัติ Next.js 15 Fullstack (App Router + Server Actions) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Next.js 15 Fullstack (App Router + Server Actions) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Next.js 15 Fullstack (App Router + Server Actions) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 3 บทเรียน

บทเรียน “การดึงข้อมูลแบบขนาน แบบลำดับ และแบบสตรีม” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Next.js 15 Fullstack (App Router + Server Actions) นี้ได้ไหม

ได้ บทเรียน Next.js 15 Fullstack (App Router + Server Actions) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การดึงข้อมูลฝั่งเซิร์ฟเวอร์
  2. การแคชและการตรวจสอบใหม่
  3. การดึงข้อมูลแบบขนาน แบบลำดับ และแบบสตรีม
← กลับไปที่ Next.js 15 Fullstack (App Router + Server Actions)