[λ΄λ³΄λ΄λ²] Understanding Next.js Data Fetching (CSR, SSR, SSG, ISR)
λ΄λ³΄λ΄λ²(λ΄κ° λ³΄λ €κ³ λ΄κ° λ²μν...) μν°ν΄
β» μμ΄ μ 곡μλ ν΄μΈ μ ννλ μλκΈ°μ λ²μμλ μμ, μ€μ, κ΅¬κΈ λ²μμ΄ λ¬΄μν λ§μ μ μμΌλ©°, κ°μΈμ μΈ κ³΅λΆ λͺ©μ μΌλ‘ λ²μνλ€ λ³΄λ μ€νλ λ§μ μ μλ€. μ νν λ΄μ©μ ν΄λΉ μν°ν΄μ μ§μ μ΄ν΄λ³΄κ±°λ λ€λ₯Έ μ 보λ€μ λ μ°Ύμ보λ κ²μ μΆμ²νλ€.
(νμ§λ§ λκΈ νΌλλ°±λ νμν©λλ€π κΈμ μ½μ΄λ³΄μκ³ λμμ μ»μΌμ ¨λ€λ©΄ μν°ν΄ μ μμ λΈλ‘κ·Έμμ μ’μμλ λλ¬μ£ΌμΈμ.)
Understanding Next.js Data Fetching (CSR, SSR, SSG, ISR) by Theodorus Clarence μλ¬Έ μ½κΈ° >>
Understanding Next.js Data Fetching (CSR, SSR, SSG, ISR) | theodorusclarence.com
Thorough explanation on Next.js data fetching method such as CSR, SSR, SSG, and ISR.
theodorusclarence.com
π μ΄ μν°ν΄μ λ²μνκ² λ μ΄μ
μ¬μ΄λ νλ‘μ νΈλ₯Ό μ§ννλ©΄μ λ΄κ° μ체μ μΌλ‘ λ§λ APIκ° μκ³ κ·Έ APIμμ λ°μ΄ν°λ₯Ό κ°μ Έμμ μ¬μ©μμκ² λ³΄μ¬μ£Όμ΄μΌ νλ νλ©΄μ΄ μμλ€. λ§€λ² λ°μ΄ν°κ° λμΌνκ² λ³΄μ¬μ§λ©΄ μ¬λ―Έκ° μμΌλ λ€μ΄μ¬ λλ§λ€ λΉ λ₯΄κ² λ‘λκ° λλ©΄μλ λλ€νκ² λ³΄μ¬μ§κΈ°λ₯Ό μνκ³ ν¬λ‘¬ Lighthouseμ μ μλ μ΄λ»κ²λ λμ¬λ³΄λ €κ³ νμμ΄ λμ΄μμλ€. κ·Έλμ Next.js Data Fetching λ¬Έμλ₯Ό 보며 μ΄κ²μ κ² μλν΄λ΄€λ κΈ°μ΅μ΄ λλ€. λͺ ννκ² SSR, SSG, ISRμ μ΄ν΄νμ§ λͺ»ν μνμμ κ΄ν revalidateλ₯Ό μΆκ°ν΄μ μ«μλ λ°κΏλ³΄κ³ λ€λ₯Έ μ΅μ λ λ£μ΄λ³΄κ³ κ·Έλ¬μλλ°... μ°μ λ¬Έμ λ ν΄κ²°νκ³ λ λ€ νμ°Έ λ€μ μ λλ‘ μ§κ³ λμ΄κ°λ©΄ μ’μ§μμκΉ νλ μκ°μ μ¬λ¬ μν°ν΄μ λ€μ Έλ΄€λ€. κ·Έλ¬λ€ λμ λ μν°ν΄μ΄ νμ¬ λ²μνλ €κ³ νλ μν°ν΄μ΄λ€. μ΄μ§ νμ΄λ§ λ΄€μ λλΆν° μ€! κ΅μ₯ν μ μ 리λ λλμ΄λ€! μΆμμ§λ§ κ°μ‘κ³ μ½μ΄μΌνλ€λ μκ°μ νλλ¬ λ―Έλ€λμλ€ μ΄μ μΌ λ²μν΄λ³Έλ€.
[λ΄λ³΄λ΄λ²] Next.js docs - Data Fetching
λ΄λ³΄λ΄λ²( λ΄κ° λ³΄λ €κ³ λ΄κ° λ²μν...) Next.js docs 2021λ 3μ 29μΌ κΈ°μ€ Next.js 곡μ λ¬Έμλ₯Ό λ²μνλ€. β» μμ΄ μ 곡μλ ν΄μΈ μ ννλ μλκΈ°μ λ²μμλ μμ, μ€μμ΄ λ¬΄μν λ§μ μ μμΌλ©°, νΌμ
birdmee.tistory.com
Introduction
When I started to learn Next.js, I got overwhelmed with the list of abbreviations that looks similar, I didn't know what it is and what is the difference. It is quite confusing because when using Create React App, we usually only use 1 strategy to fetch data from API which is using useEffect.
λ΄κ° μ²μμΌλ‘ Next.jsλ₯Ό λ°°μ°κΈ° μμνμ λ λκ° λΉμ·ν΄λ³΄μ΄λ μ½μ΄λ€μ λͺ©λ‘μ λ³΄κ³ λΉν©μ€λ¬μ λ€. κ·Έκ² λμ§λ λͺ¨λ₯΄κ³ μ°¨μ΄μ λ λͺ°λμλ€. κ½€ ν·κ°λ Έλλ° Create React Appμ μ¬μ©ν λ λκ° ν κ°μ§ μ λ΅, useEffectλ₯Ό μ¬μ©νμ¬ APIλ‘λΆν° λ°μ΄ν°λ₯Ό κ°μ Έμ€κΈ° λλ¬Έμ΄λ€.
Next.js has many data fetching strategies. Although initially Next.js was well known to be a Server-Side Rendering Framework, it turns out that Next.js has 4 methods of Data Fetching. Here is the short explanation each so you get familiar with the abbreviation of CSR, SSR, SSG, ISR.
Next.jsλ λ°μ΄ν°λ₯Ό κ°μ Έμ€λ μ¬λ¬ μ λ ₯λ€μ΄ μλ€. Next.jsκ° μ²μμλ μλ² μ¬μ΄λ λ λλ§ νλ μμν¬λ‘ μ μλ €μ§κΈ΄ νμ§λ§, Next.jsλ λ°μ΄ν°λ₯Ό κ°μ Έμ€λ 4κ°μ§ λ°©λ²μ΄ μκ² λμλ€. μ΄μ μ¬λ¬λΆμ΄ CSR, SSR, SSG, ISRμ΄λΌλ μ½μ΄μ μ΅μν΄μ§λλ‘ μ§§κ² μ€λͺ μ μ§ννκ² λ€.
- CSR - Client-Side Rendering, this is the usual kind of data fetching using useEffect, it will fetch the data from the API every single page request on the client-side (after the page is rendered, then the function will run).
- SSR - Server-Side Rendering, will run a special function to fetch data from API every page request on the server-side (before the page is loaded, that special function will run first, creating a delay, then after that, it will serve the page).
- SSG - Static Site Generation, will run a special function to fetch data once when that page builds.
- ISR – Incremental Static Regeneration, this is a new thing, shortly put, a combination of SSG, and SSR, where it served statically, but at a certain time and certain condition that page will rebuild and fetch the data from the API again.
- CSR - Client-Side Rendering, μ΄κ²μ useEffectλ₯Ό μ¬μ©νμ¬ λ°μ΄ν°λ₯Ό κ°μ Έμ€λ κ²κ³Ό κ°μ μ’ λ₯μ λ°©λ²μΌλ‘, ν΄λΌμ΄μΈνΈ μΈ‘μμ λ§€ μ±κΈ νμ΄μ§ μμ²λ§λ€ APIλ‘λΆν° λ°μ΄ν°λ₯Ό κ°μ Έμ¨λ€. (νμ΄μ§κ° λ λλκ³ λ ν, ν¨μκ° λμνλ€.)
- SSR - Server-Side Rendering, μλ² μΈ‘μμ λ§€ νμ΄μ§ νΈμΆλ§λ€ νΉλ³ν ν¨μλ₯Ό λμμμΌ APIλ‘λΆν° λ°μ΄ν°λ₯Ό κ°μ Έμ¨λ€. (νμ΄μ§κ° λ‘λλκΈ° μ μ, κ·Έ νΉλ³ν ν¨μκ° λ¨Όμ λμνκ³ λλ μ΄λ₯Ό λ§λ€κ³ κ·Έ νμ νμ΄μ§λ₯Ό κ°μ Έμ¨λ€.)
- SSG - Static Site Generation, νμ΄μ§κ° λΉλλ λ νΉλ³ν ν¨μλ₯Ό λμμμΌ λ°μ΄ν°λ₯Ό κ°μ Έμ¨λ€.
- ISR - Incremental Static Regeneration, μλ‘μ΄ λ°©λ²μΈλ° μ§§κ² μ€λͺ νμλ©΄ SSGμ SSRμ κ²°ν©μΌλ‘ μ μ μΌλ‘ μ 곡νλ κ³³μμ νΉμ μκ°κ³Ό νΉμ 쑰건μ ν΄λΉ νμ΄μ§κ° μ¬λΉλλκ³ APIμμ λ°μ΄ν°λ₯Ό λ€μ κ°μ Έμ¨λ€.
Don't worry if you didn't get that, because I will be explaining it thoroughly, just familiarize the words first.
μ² μ ν μ€λͺ μ ν΄μ€ν λ μ΄ν΄κ° μλλ€ν΄λ κ±±μ λ§λΌ, λ¨Όμ λ¨μ΄μ μ΅μν΄μ§λλ‘ νμ.
I mentioned before that there is a special function that will run when using a specific data fetching method. Keep that in mind as I will show you what is that special function.
μμ μΈκΈνλ κ²μ²λΌ νΉμ λ°μ΄ν° κ°μ Έμ€κΈ° λ©μλλ₯Ό μ¬μ©ν λ λμνλ νΉλ³ν ν¨μκ° μλ€. κ·Έ νΉλ³ν ν¨μκ° λ¬΄μμΈμ§ 보μ¬μ€ν λ μ°Έκ³ νλΌ.
This code example will fetch a date-time from an API using axios, then render it on the page. It is useful to see the date-time so we can truly know when the API is hit.
μ¬κΈ°μ μ½λ μμλ axiosλ₯Ό μ¬μ©ν΄μ APIλ‘λΆν° λ μ§μ μκ°μ κ°μ Έμ€κ³ νμ΄μ§μ λ λνλ€. λ μ§μ μκ°μ 보λ κ²μ΄ μ μ©ν κ²μ APIμ μΈμ μ κ·Όλλμ§ μ μ μκΈ° λλ¬Έμ΄λ€.
Client-Side Rendering (CSR)
Special Function: `useEffect`
Code Example
export default function CSRPage() {
const [dateTime, setDateTime] = React.useState<string>();
React.useEffect(() => {
axios
.get('https://worldtimeapi.org/api/ip')
.then((res) => {
setDateTime(res.data.datetime);
})
.catch((error) => console.error(error));
}, []);
return (
<main>
<TimeSection dateTime={dateTime} />
</main>
);
}
Demo
Terms:
- PT → Preview Time, the time shown when the API is hit. Can be seen in the middle.
- RT → Real-Time, the real ticking time updating every second, can be seen on the right bottom corner
- PT → 미리보기 μκ°, APIμ μ κ·Όνμ λμ μκ°. μ€κ°μ 보μ¬μ§.
- RT → μ€μ μκ°, λ§€μ΄ μ λ°μ΄νΈλλ μ€μ μκ°μΌλ‘ μ°μΈ‘ νλ¨ μ½λμ 보μ¬μ§.
Video Description:
- Page reloads on 15:46:03 Real-Time (RT), then a LOADING indicator is shown
- After about 1s, Preview Time is showing 15:46:04(PT)
- 15:46:03 μ€μ μκ°(RT)μ νμ΄μ§κ° μ¬λ‘λλκ³ LOADING νμκ° λ³΄μ¬μ§
- 1μ΄ μ―€ νμ 미리보기 μκ° 15:46:04(PT)κ° λ³΄μ¬μ§
Keys to Emphasize
- useEffect function, this function is the key indicator that a page is using Client-Side Rendering.
- LOADING indicator, because the data fetching runs after the page is rendered, the data is not fetched instantly, therefore showing a loading state.
- Data is fetched on every page request, which is why the time shown is different for each reloads.
- useEffect ν¨μ, μ΄ ν¨μλ νμ΄μ§κ° Client-Side Rendingμ μ¬μ©νκ³ μλ€λ ν΅μ¬ μμμ΄λ€.
- LOADING νμ, λ°μ΄ν° κ°μ Έμ€κΈ°κ° νμ΄μ§κ° λ λλ ν μ€νλκΈ° λλ¬Έμ, λ°μ΄ν°λ μ¦μ ν¨μΉλλ κ²μ΄ μλκ³ λ°λΌμ λ‘λ© μνκ° λ³΄μ¬μ§λ€.
- λ°μ΄ν°λ λ§€ νμ΄μ§ μμ²λ§λ€ ν¨μΉλλ€, κ·Έλ κΈ° λλ¬Έμ κ° μ¬λ‘λ λ§λ€ λ€λ₯Έ μκ°μ΄ 보μ¬μ§λ€.
Server Side Rendering (SSR)
Special Function: `getServerSideProps`
Code Example
export default function SSRPage({ dateTime }: SSRPageProps) {
return (
<main>
<TimeSection dateTime={dateTime} />
</main>
);
}
export const getServerSideProps: GetServerSideProps = async () => {
const res = await axios.get('https://worldtimeapi.org/api/ip');
return {
props: { dateTime: res.data.datetime },
};
};
Demo
Video Description:
- Clicked the link on 16:32:38(RT), a slight pause for 2s, then page loads showing 16:02:40(PT)
- 16:02:38(RT)*μ λ§ν¬λ₯Ό ν΄λ¦νκ³ , μ½ 2μ΄ μ λμ λ©μΆ€ νμ, 16:02:40(PT) 보μ΄λ νμ΄μ§κ° λ‘λλλ€.
(* μλ¬Έμ 16:32:38μ΄ μ€νμΈ κ² κ°μμ λ²μμ 16:02:38λ‘ μμ ν¨.)
Keys to Emphasize
- getServerSideProps function, this function is the key indicator that a page is using Server-Side Rendering.
- DELAY before render, and no LOADING indicator, the data is fetched before the page is rendered, so there will be a slight delay where the API is being hit at the moment, then it will show the page without loading indicator
- Data is fetched on every page request, which is why the time shown is different for each reloads.
- getServerSideProps ν¨μ, μ΄ ν¨μλ νμ΄μ§κ° Server-Side Rendingμ μ¬μ©νλ€λ ν΅μ¬ μμμ΄λ€.
- λ λ μ λλ μ΄, κ·Έλ¦¬κ³ LOADING νμκ° μμ, λ°μ΄ν°λ νμ΄μ§κ° λ λλκΈ° μ μ ν¨μΉλκ³ κ·Έλ κΈ° λλ¬Έμ APIκ° μ κ·Όνλ μκ°μ μ½κ° λλ μ΄κ° λ°μν νμ λ‘λ© νμ μμ΄ νμ΄μ§μ 보μ¬μ§λ€.
- λ°μ΄ν°λ λ§€ νμ΄μΉ μμ²λ§λ€ ν¨μΉλλ€, μ΄κ²μ΄ κ° μ¬λ‘λ λ§λ€ λ€λ₯Έ μκ°μ΄ 보μ¬μ§λ μ΄μ μ΄λ€.
CSR vs SSR
Here is the difference between CSR vs SSR, keep an eye on delay and loading indicators.
μ΄μ CSRκ³Ό SSR μ¬μ΄μ μ°¨μ΄μ μ λν΄ μ΄μΌκΈ°νλ λλ μ΄μ λ‘λ© νμμ μ£Όμν΄λ³΄μ.
Video Description:
- When clicking CSR, with no delay a LOADING text is visible for a second, then the Preview Time loads.
- When clicking SSR, a slight delay happened, then the page loads.
- CSRμ ν΄λ¦νλ©΄ λλ μ΄ μμ΄ LOADING ν μ€νΈκ° μ κΉ λ³΄μ¬μ§κ³ Preview μκ°μ΄ λ‘λλλ€.
- SSRμ ν΄λ¦νλ©΄ μ½κ°μ λλ μ΄ νμ νμ΄μ§κ° λ‘λλλ€.
Keys to Emphasize
- CSR hit the API after the page loads.
- SSR hit the API before the page loads.
- CSRμ νμ΄μ§ λ‘λ νμ APIμ μ κ·Όνλ€.
- SSRμ νμ΄μ§ λ‘λ μ μ APIμ μ κ·Όνλ€.
Short addition
I will probably create a new post about the pros and cons of each method, but when using CSR the SEO is not really great because the data is only fetched after the page renders. This is useful and convenient when we are creating a page with a gated authentication, as you don't really need SEO for pages like the dashboard, edit profile page, etc.
μλ§λ κ° λ©μλμ μ₯λ¨μ μ λν΄ μλ‘μ΄ ν¬μ€νΈλ₯Ό μμ±ν κ²μ΄κΈ΄ νμ§λ§ CSRμ μ¬μ©ν λ SEOμλ κ·Έλ€μ§ μ’μ§ μλλ° μλνλ©΄ λ°μ΄ν°κ° νμ΄μ§κ° λ λλ νμλ§ κ°μ Έμμ§κΈ° λλ¬Έμ΄λ€. μ΄ λ°©λ²μ λμ보λλ νλ‘ν μμ νμ΄μ§μ κ°μ SEOκ° λ³λ‘ νμκ° μλ κ²μ΄νΈ μΈμ¦μ΄ μλ νμ΄μ§λ₯Ό μμ±ν λ μ μ©νκ³ νΈλ¦¬νλ€.
But, for the SSR, although it creates a delay, data that was fetched is injected and helps SEO. This is quite useful for a thread or post that we need to get traffic into, like Reddit or some sort.
νμ§λ§ SSRμ λν΄μλ λλ μ΄κ° μκΈ°λ νμ§λ§ κ°μ Έμ¨ λ°μ΄ν°κ° μ£Όμ λμκ³ SEOμλ λμμ΄ λλ€. μ΄ λ°©λ²μ Redditμ΄λ κ·Έμ λΉμ·ν μ’ λ₯μ νΈλν½μ κ°μ ΈμμΌνλ μ€λ λλ ν¬μ€νΈμ μ μ©νλ€.
Static Site Generation (SSG)
Special function: `getStaticProps`
Code Example
export default function SSGPage({ dateTime }: SSGPageProps) {
return (
<main>
<TimeSection dateTime={dateTime} />
</main>
);
}
export const getStaticProps: GetStaticProps = async () => {
const res = await axios.get('https://worldtimeapi.org/api/ip');
return {
props: { dateTime: res.data.datetime },
};
};
Demo
Video Description:
- Preview Time is showing 13:39:36(PT). But the real-time is 16:16:59(RT), about 3 hours late.
- Reloading and going back and forth to the home page did not change anything.
- 미리보기 μκ°μ 13:39:36(PT)λ‘ λ³΄μ¬μ€λ€. νμ§λ§ μ€μ μκ°μ 16:16:59(RT)λ‘ 3μκ° μ λ λ¦λ€.
- μ¬λ‘λ©νκ³ μλ€λ‘ ν νλ©΄μΌλ‘ κ°λ€ λμμλ€ ν΄λ΄λ νμ΄μ§λ μ무κ²λ λ°λμ§ μλλ€.
Keys to Emphasize
- getStaticProps function, this function is the key indicator that a page is using Static Site Generation.
- Fetched when running yarn build, the API will be hit ONLY when the application is building. This is why the time is at 13:39, while the real-time is 16:17.
- Data will not change because no further fetch, which is why the time shown is the same for each reloads.
- getStaticProps ν¨μ, μ΄ ν¨μλ νμ΄μ§κ° Static Site Generationμ μ¬μ©νκ³ μλ€λ ν΅μ¬ μμμ΄λ€.
- yarn buildκ° μ€νλ λ λ°μ΄ν°λ₯Ό κ°μ Έμ΄, μ ν리μΌμ΄μ μ΄ λΉλλ λμλ§ APIμ μ κ·Όνλ€. μ΄κ²μ΄ μ€μ μκ°μ 16:17μΈλ°λ 13:39λ‘ λ³΄μ¬μ§λ μ΄μ μ΄λ€.
- μΆκ° ν¨μΉκ° μκΈ° λλ¬Έμ λ°μ΄ν°λ λ°λμ§ μλλ€, κ·Έλ κΈ° λλ¬Έμ λ§€λ² μ¬λ‘λν λλ§λ€ λμΌν μκ°μ 보μ¬μ€λ€.
Incremental Static Regeneration
Special function: `getStaticProps` + `revalidate`
Code Example
export default function ISR20Page({ dateTime }: ISR20PageProps) {
return (
<main>
<TimeSection dateTime={dateTime} />
</main>
);
}
export const getStaticProps: GetStaticProps = async () => {
const res = await axios.get('https://worldtimeapi.org/api/ip');
return {
props: { dateTime: res.data.datetime },
revalidate: 20,
};
};
Demo
Disclaimer: Revalidate time is set to 20 seconds.
μ£Όμ: κ°±μ μκ°μ 20μ΄λ‘ μ€μ λμ΄ μμ.
Video Description:
- At first, it was 16:40:12(PT), and real-time when reloading is 16:40:25(RT) and 16:40:29(RT). In those 2 reload, Preview Time (PT) did not change.
- Then, when 16:40:32(RT) (20s after initial), reload is done twice, the first time on 16:40:36(RT) and 16:40:40(RT). The Preview Time change to 16:40:37(PT) after the second reload.
- 맨 μ²μ 16:40:12(PT)μλ€. κ·Έλ¦¬κ³ μ¬λ‘λ©λ λ μ€μ μκ°μ 16:40:25(RT) κ·Έλ¦¬κ³ 16:40:29(RT)μ΄λ€. μ΄ 2λ²μ μ¬λ‘λμμ, 미리보기 μκ° (PT)λ λ³νμ§ μλλ€.
- κ·Έλ¦¬κ³ , 16:40:32(PT)μΌ λ (μ²μμΌλ‘λΆν° 20μ΄ ν), μ¬λ‘λλ₯Ό 2λ² νμλ€. 첫 λ²μ§Έλ 16:40:36(RT)μ κ·Έλ¦¬κ³ 16:40:40(RT)μ΄μλ€. 미리보기 μκ°μ 16:40:37(PT)λ‘ λλ²μ§Έ μ¬λ‘λ νμ λ³κ²½λμλ€.
Keys to Emphasize
Now, this is might be confusing for you, but here is the key I want you to look at.
μ’ ν·κ°λ¦΄ μλ μμ§λ§ μ¬κΈ°μ λ μλ€μ΄ 보μμΌλ©΄ νλ ν΅μ¬μ΄ μλ€.
- When in a 20-second cooldown span–16:40:12(RT) - 16:40:32(RT), reloading doesn't trigger changes. This is because the page is in a cooldown state, as we set on the revalidate key.
- After the 20-second cooldown–16:40:32(RT), we did 2 reloads.
- First Reload at 16:40:36(RT), we know that it is not on the cooldown state anymore. The first visit after the cooldown state is off, is going to trigger page rebuild. Page rebuild meaning, only this certain page is going to be rebuild. Not the whole application. The fetch API will run in the background, but there will be no changes on the Preview Time
- Second Full Reload at 16:40:40(RT), the Preview Time change to 16:40:37(PT). Exactly a second after the page rebuild (which means the rebuild takes about 1s). This second reload is going to serve that rebuilt page from the previous reload.
- 20μ΄μ μΏ¨λ€μ΄ κΈ°κ° λμ–16:40:12(RT) - 16:40:32(RT), μ¬λ‘λλ λ³κ²½μ¬νμ΄ νΈλ¦¬κ±°λμ§ μλλ€. μ΄κ²μ μ°λ¦¬κ° revalidate ν€λ₯Ό μ€μ ν΄λμλλ‘ ν΄λΉ νμ΄μ§κ° μΏ¨λ€μ΄ μνμ μκΈ° λλ¬Έμ΄λ€.
- 20μ΄μ μΏ¨λ€μ΄ νμ–16:40:32(RT), 2λ²μ μ¬λ‘λλ₯Ό νλ€.
- 첫λ²μ§Έ μ¬λ‘λλ 16:40:36(RT) μ΄μλ€. μ΄ μμ μ λ μ΄μ μΏ¨λ€μ΄ μνμ μμ§ μλ€λ κ²μ μ°λ¦¬λ μλ€. μΏ¨λ€μ΄ μνκ° μ’ λ£λκ³ λ νμ 첫λ²μ§Έ λ°©λ¬Έμ νμ΄μ§ μ¬λΉλλ₯Ό νΈλ¦¬κ±° νλ€. νμ΄μ§ μ¬λΉλμ μλ―Έλ ν΄λΉλλ μ΄ νΉμ νμ΄μ§λ§ μ¬λΉλ λλ€λ κ²μ΄λ€. μ 체 μ ν리μΌμ΄μ μ΄ μ¬λΉλ λλ κ²μ΄ μλλ€. ν¨μΉ APIλ λ°±κ·ΈλΌμ΄λμμ λμνμ§λ§ 미리보기 μκ°μλ λ³νκ° μμ κ²μ΄λ€.
- λλ²μ§Έ μλ‘κ³ μΉ¨(*μλμ μ©μ΄ μ€λͺ μ΄ λμ΄)λ 16:40:40(RT)μ΄λ€. 미리보기 μκ°μ 16:40:37(PT)λ‘ λ°λμλ€. νμ΄μ§ μ¬λΉλλκ³ μ λ§ μ κΉ νμ λ§μ΄λ€. (μ΄κ²μ μ¬λΉλνλλ° μ½ 1μ΄ μ λ κ±Έλ¦°λ€λ λ»μ΄λ€.) μ΄ λλ²μ§Έ μ¬λ‘λλ μ΄μ μ¬λ‘λλ‘λΆν° μ¬λΉλλ νμ΄μ§λ₯Ό 보μ¬μ€ κ²μ΄λ€.

Revisiting Page vs Full Reload

Terms:
- Revisiting pages → navigating using next/link (going back to home, then to that page again)
- Full reload → doing reload at a website (command+r)
- νμ΄μ§ μ¬λ°©λ¬Έ → next/linkλ₯Ό μ¬μ©νμ¬ μ΄λνλ κ² (νμΌλ‘ λμκ°λ€κ° ν΄λΉ νμ΄μ§λ‘ λ€μ μ€λ κ²)
- μλ‘κ³ μΉ¨ → μΉμ¬μ΄νΈμμ μλ‘κ³ μΉ¨/μ¬λ‘λνλ κ² (command+r)
Video Description:
- Revisiting pages at the first time 18:38:45(RT), will trigger rebuild, but after the second revisit, the Preview Time did not change.
- After a full reload, then Preview Time is changed to 18:38:45(PT)
- 18:38:45(RT)μ μ²μμΌλ‘ νμ΄μ§λ₯Ό μ¬λ°©λ¬Έ νλ κ²μ, μ¬λΉλλ₯Ό νΈλ¦¬κ±°ν κ²μ΄μ§λ§, λ λ²μ§Έ μ¬λ°©λ¬Έ νμ 미리보기 μκ°μ λ³νμ§ μμλ€.
- μλ‘κ³ μΉ¨νμλ, 미리보기 μκ°μ΄ 18:38:45(PT)λ‘ λ°λμλ€.
Note:
- The first reload does not have to be a full reload, we can go back to the home page, then to that page again (revisit), it will trigger the rebuild as long as we are not in the cooldown state.
- But, the second reload must be a full reload. Going back to the home page, then to the page again won't change the new Preview Time.
- 첫λ²μ§Έ μ¬λ‘λλ ν μ¬λ‘λμΌ νμλ μλ€. ν νλ©΄μΌλ‘ λμκ°λ€κ° ν΄λΉ νμ΄μ§λ‘ λ€μ λμμλ λλ€(μ¬λ°©λ¬Έ). μ΄λ κ² νλ κ²μ μΏ¨λ€μ΄ μνκ° μλ ν μ¬λΉλλ₯Ό νΈλ¦¬κ±°ν κ²μ΄λ€.
- νμ§λ§, λλ²μ§Έ μ¬λ‘λλ λ°λμ μλ‘κ³ μΉ¨μ΄μ΄μΌλ§ νλ€. ν νλ©΄μΌλ‘ λμκ°λ€κ° ν΄λΉ νμ΄μ§λ‘ λ€μ λμμ€λ κ²μ μλ‘μ΄ λ―Έλ¦¬λ³΄κΈ° μκ°μΌλ‘ λ°κΎΈμ§ μμ κ²μ΄λ€.
Now, this is a case where we are assuming that only 1 person is accessing the website. But, that reloads will happen every person visit while still respecting the cooldown state.
μ΄κ²μ μ°λ¦¬κ° λ¨ ν λͺ λ§μ΄ μ΄ μΉμ¬μ΄νΈμ μ κ·Όνλ€κ³ κ°μ νμ λμ΄λ€. κ·Έλ°λ° μ΄ μ¬λ‘λλ μΏ¨λ€μ΄ μνλ₯Ό μ μ§νλ©΄μ λ°©λ¬Ένλ λͺ¨λ μ¬λμκ² λ°μνλ€.
Is it going to be rebuilt every 20s then?
κ·ΈλΌ λ§€ 20μ΄λ§λ€ μ¬λΉλκ° μ΄λ£¨μ΄μ§λκ°?
Nope.
κ·Έλ μ§ μλ€.
When the cooldown is off, if no one visits the page, then that page will not rebuild, even after long past the 20s.
μΏ¨λ€μ΄μ΄ μ’ λ£λκ³ μ무λ νμ΄μ§λ₯Ό λ°©λ¬Ένμ§ μμΌλ©΄ νμ΄μ§λ 20μ΄κ° μ§λ νμλ μ¬λΉλ λμ§ μμ κ²μ΄λ€.
But, the first person that visits when the cooldown state is off, is going to trigger a rebuild. That person won't be seeing changes. But, the changes will be served for the next full reload.
νμ§λ§ 첫 λ²μ§Έ μ¬λμ΄ μΏ¨λ€μ΄ μνκ° μ’ λ£λμμ λ λ°©λ¬Ένλ©΄ μ¬λΉλλ νΈλ¦¬κ±° λ κ²μ΄λ€. κ·Έ μ¬λμ λ°λ λ΄μ©μ λ³΄μ§ λͺ»ν κ²μ΄λ€. νμ§λ§ ν΄λΉ λ³νλ λ€μ μλ‘κ³ μΉ¨ λμ 보μ¬μ§ κ²μ΄λ€.
Conclusion
That's all, folks!
If you have understood this material, I suggest you to read more about How to choose between them. I provide 4 metrics for you to consider and some example!
μ΄ κΈμ μ΄ν΄νλ€λ©΄, How to choose between themμ λν΄ λ μ½μ΄λ³΄κΈ° λ°λλ€. λΉμ μ΄ κ³ λ €ν΄μΌν 4κ°μ§ μΈ‘μ νλͺ©κ³Ό λͺ κ°μ§ μμ λ μ 곡νλ€.
(κΈμ΄ μ μ΅νμ ¨μΌλ©΄ μν°ν΄ μ μμ λΈλ‘κ·Έμμ μ’μμλ λλ¬μ£ΌμΈμππ)
λ€μ μν°ν΄ How to choose between them νμΈνλ¬κ°κΈ°π
[λ΄λ³΄λ΄λ²] How to choose between Next.js CSR, SSR, SSG, and ISR
λ΄λ³΄λ΄λ²( λ΄κ° λ³΄λ €κ³ λ΄κ° λ²μν... ) μν°ν΄ β» μμ΄ μ 곡μλ ν΄μΈ μ ννλ μλκΈ°μ λ²μμλ μμ, μ€μ, κ΅¬κΈ λ²μμ΄ λ¬΄μν λ§μ μ μμΌλ©°, κ°μΈμ μΈ κ³΅λΆ λͺ©μ μΌλ‘ λ²μνλ€ λ³΄λ μ€
birdmee.tistory.com