Just keep coding ...๐Ÿ’–โœŒ๏ธ

[Next.js] (5) - ์‚ฌ์ „๋ Œ๋”๋ง (SSR, SSG)

2024. 11. 5. 08:02ใ†front-end/Next.js

728x90

๐Ÿ‘‰  Next.js ๋‹ค์–‘ํ•œ ์‚ฌ์ „ ๋ Œ๋”๋ง

  1. ์„œ๋ฒ„์‚ฌ์ด๋“œ ๋ Œ๋”๋ง (SSR)
    • ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ์‚ฌ์ „ ๋ Œ๋”๋ง ๋ฐฉ์‹
    • ์š”์ฒญ์ด ๋“ค์–ด์˜ฌ ๋•Œ ๋งˆ๋‹ค ์‚ฌ์ „ ๋ Œ๋”๋ง์„ ์ง„ํ–‰ํ•จ
  2. ์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ(SSG)
    • ๋นŒ๋“œ ํƒ€์ž„์— ๋ฏธ๋ฆฌ ํŽ˜์ด์ง€๋ฅผ ์‚ฌ์ „ ๋ Œ๋”๋ง ํ•ด ๋‘ 
  3. ์ฆ๋ถ„ ์ •์  ์žฌ์ƒ์„ฑ (ISR)
    • ํ–ฅํ›„์— ๋‹ค๋ฃฐ ์‚ฌ์ „ ๋ Œ๋”๋ง ๋ฐฉ์‹

 

 

๐Ÿ‘‰  SSR - ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง (์š”์ฒญ์ด ๋“ค์–ด์˜ฌ ๋•Œ ๋งˆ๋‹ค ์‚ฌ์ „ ๋ Œ๋”๋ง์„ ์ง„ํ–‰)

export const getServerSideProps = () => {
  // ์ปดํฌ๋„ŒํŠธ๋ณด๋‹ค ๋จผ์ € ์‹คํ–‰, ์ปดํฌ๋„ŒํŠธ์— ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๋Š” ํ•จ์ˆ˜
  // ์˜ค์ง ์„œ๋ฒ„์ธก์—์„œ๋งŒ ํ•œ ๋ฒˆ ์‹คํ–‰
  const data = 'hello'

  return {
    //๋‹จ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋ฅผ ๋ฆฌํ„ด, props ํ”„๋กœํผํ‹ฐ๊ฐ’์„ ๋„ฃ์–ด์•ผํ•จ
    props: {
      data,
    },
  }
}
props: InferGetServerSidePropsType<typeof getServerSideProps> 
//getServeSideProps ๋ฐ˜ํ™˜๊ฐ’ ํƒ€์ž…์„ ์ž๋™์œผ๋กœ ์ถ”๋ก ํ•ด์ค€๋‹ค.

 

๐Ÿ‘‰  ๋ธŒ๋ผ์šฐ์ €์—์„œ๋งŒ ์‹คํ–‰์„ ์›ํ•˜๋Š” ๊ฒฝ์šฐ

  • useEffect() ๋ฅผ ์ด์šฉํ•ด์„œ ํŽ˜์ด์ง€๊ฐ€ mount ๋œ ์ดํ›„์— ๋ถˆ๋Ÿฌ ์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ํ•จ

 

๐Ÿ‘‰  SSG - ์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ (Build Time ์— ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด ๋†“์Œ!)

  • ์‚ฌ์ „ ๋ Œ๋”๋ง์— ๋งŽ์€ ์‹œ๊ฐ„์ด ์†Œ์š”๋˜๋Š” ํŽ˜์ด์ง€๋”๋ผ๋„ ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์—๋Š” ๋งค์šฐ ๋น ๋ฅธ์†๋„๋กœ ์‘๋‹ต ๊ฐ€๋Šฅ
  • ์ตœ์‹  ๋ฐ์ดํ„ฐ ๋ฐ˜์˜์€ ์–ด๋ ต๋‹ค. - ์ •์ ์ธ ํŽ˜์ด์ง€์— ์ ํ•ฉํ•œ ๊ธฐ๋Šฅ

 

 

์ถœ์ฒ˜: https://www.inflearn.com/course/%ED%95%9C%EC%9E%85-%ED%81%AC%EA%B8%B0-nextjs/dashboard

 

ํ•œ ์ž… ํฌ๊ธฐ๋กœ ์ž˜๋ผ๋จน๋Š” Next.js(15+) ๊ฐ•์˜ | ์ด์ •ํ™˜ Winterlood - ์ธํ”„๋Ÿฐ

์ด์ •ํ™˜ Winterlood | ํ•œ์ž… ์‹œ๋ฆฌ์ฆˆ์˜ 3๋ฒˆ์งธ ์ž‘ํ’ˆ! ์„ธ์ƒ์—์„œ ๊ฐ€์žฅ ์นœ์ ˆํ•˜๊ณ  ๋””ํ…Œ์ผ ํ•œ Next.js(15+)๊ฐ•์˜ ์ž…๋‹ˆ๋‹ค. App Router ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ Page Router๊นŒ์ง€ ํ”„๋กœ์ ํŠธ๋ฅผ ํ†ตํ•ด ์‚ดํŽด๋ด…๋‹ˆ๋‹ค., [์ž„๋ฒ ๋”ฉ ์˜์ƒ]ํ•œ ์ž… ํฌ๊ธฐ

www.inflearn.com

 

728x90