| CSR | SSR | SSG | ISR | |
|---|---|---|---|---|
| 빌드시간 | 짧다 | 짧다 | 길다 | 길다 |
| SEO | 나쁨 | 좋음 | 좋음 | 좋음 |
| 페이지 요청에 따른 응답 시간 | 보통 | 길다 | 짧다 | 짧다 |
| 최신 정보인가? | 맞음 | 맞음 | 아님 | 아닐 수 있음 |
구현방법
"use client;" 최상단에 사용하여 해당 컴포넌트를 서버 컴포넌트에 삽입
구현결과
요청이 있을 때 마다 지속해서 갱신 / loading에 관련된 state 제어를 통해 사용자에게 알려줄 수 있음
구현방법
fetch에 no-store 옵션 주기const ProductsPage = async () => { const response = await fetch('http://localhost:4000/products', {cache: "no-store"}); const products: Product[] = await response.json();구현결과
요청이 있을 때 마다 지속해서 갱신 / hydration이 완료되기 전까지의 시간; TTI(Time To Interactive)가 관건
구현방법
1) fetch에 아무 옵션 주지 않기(기본값)
2) fetch에 force-cache 옵션 주기const HomePage = async () => { const response = await fetch('http://localhost:4000/products', {cache: "force-cache"}); const products: Product[] = await response.json();구현결과
아무리 새로고침을 하여도 동일한 페이지만 출력
구현방법
1) fetch에 next 옵션주기const ProductsPage = async () => { const response = await fetch('http://localhost:4000/products', next: { revalidate: 5, }, ); const products: Product[] = await response.json();2) page.tsx 컴포넌트에 revalidate 추가하기(next 옵션은 지우기)
export const revalidate = 5; const HomePage = async () => { const response = await fetch('http://localhost:4000/products'); const products: Product[] = await response.json();구현결과
주어진 시간에 한 번씩 갱신