Next.js

[Next.js] CSR(client side render) vs SSR(server side render)

jjingle 2024. 3. 15. 11:27

* Rendering : js code๋ฅผ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” html๋กœ ๋ฐ”๊พธ๋Š” ๊ฒƒ

 

- React render :  CSR (client side rendering)

  • create-react-app ์„ ์‚ฌ์šฉํ•ด react๋งŒ์œผ๋กœ application์„ ์ƒ์„ฑํ•˜๋ฉด , client side rendering
  • client side rendering => ์‚ฌ์šฉ์ž ๋ธŒ๋ผ์šฐ์ €์ธ client๋‹จ์—์„œ rendering ์ž‘์—…์„ ํ•œ๋‹ค.
  • ๋‹จ์  
    1. ํŽ˜์ด์ง€์˜ ์‹ค์ œ ์†Œ์Šค์ฝ”๋“œ๋Š” ๋น„์–ด์žˆ๋‹ค.
      • ex. <div id='root'></div>
      • = UI๊ฐ€ ์—†๋‹ค
      • ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋ชจ๋“  JS ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ , ์‹คํ–‰ํ•œ ํ›„์—์•ผ ํ™”๋ฉด์— ๋ณด์—ฌ์ง€๋Š” ๊ฒƒ
      • ์ƒˆ๋กœ๊ณ ์นจ ์‹œ, JS์—”์ง„์ด ์œ„์˜ ์‚ฌํ•ญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์‹œ๊ฐ„ ๋™์•ˆ ๋นˆ ํ™”๋ฉด์ด ๋ณด์—ฌ์ง
    2. SEO, ๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™”
      • Search Engine Optimization
      • Google์€ ํŽ˜์ด์ง€์˜ HTML์„ ๋ณธ๋‹ค -> ๊ตฌ๊ธ€์— ๋…ธ์ถœ์„ ์œ„ํ•ด์„ , ๋นˆํŽ˜์ด์ง€๋ฅผ ๋ณด์—ฌ์ฃผ์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.
      • ๊ฒ€์ƒ‰์—”์ง„์€ JS๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๊ทธ ์•ˆ์— ์ฝ”๋“œ๋ฅผ ๋ณด์ง€ ์•Š๋Š”๋‹ค.

 

- Next.js render :  SSR (server side rendering)

  • next.js๋กœ ์›น์‚ฌ์ดํŠธ๋ฅผ ๋นŒ๋“œํ•˜๋ฉด ์ž๋™์œผ๋กœ,  server side rendering
  • HTML์„ ๋ณด์—ฌ์ฃผ๋Š”๋ฐ JavaSript๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค
  • next.js application์˜ ๋ชจ๋“  page ์•ˆ์˜ ๋ชจ๋“  component ๋“ค์€, next.js๊ฐ€ ์šฐ์„  server(backend)์—์„œ renderํ•œ๋‹ค.
    • -> ๋ชจ๋“  component๋ฅผ renderํ•œ html์„ ๋ธŒ๋ผ์šฐ์ € request์— ๋Œ€ํ•œ response๋กœ ์คŒ
    • ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‚ฌ์šฉ์ž๋Š” ์ž ๊น์ด๋ผ๋„(์ƒˆ๋กœ๊ณ ์นจ) ๋น„์–ด์žˆ๋Š” html์„ ๋ณด์ง€ ์•Š์Œ
    • server component, client component ์ „๋ถ€ backend์—์„œ render

'Next.js' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Next.js] fetch data, React vs Next.js  (0) 2024.03.19
[Next.js] Server component vs Client component  (0) 2024.03.19
[Next.js] Library vs Framework  (1) 2024.03.15
[Next.js] Next ํ”„๋กœ์ ํŠธ ์ˆ˜๋™ setup  (0) 2024.03.14