๐ŸŒ HTTP/2์™€ Webpack

DoonDoonยท2018๋…„ 10์›” 21์ผ
4
post-thumbnail
post-custom-banner

TL;DR
์ด๋ฏธ ์›นํŒฉ์€ HTTP/2 ์™€ ๊ด€๊ณ„ ์—†์ด๋„ ๋งŽ์€ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์žˆ์œผ๋ฉฐ
HTTP/2 ์—์„œ ์›นํŒฉ์˜ ๋ฒˆ๋“ค๋ง ์ „๋žต์— ๋”ฐ๋ผ, ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ๋„๋ชจํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

Overview


Webpack ์„ค์ •ํŒŒ์ผ์„ ์—ด์‹ฌํžˆ ์ž‘์„ฑํ•˜๋‹ค ๋ฌธ๋“ HTTP/2 ๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์†Œ์Šค ๋กœ๋”ฉ๋„ ๋น ๋ฅด๋‹ค๋Š”๋ฐ
(2018๋…„ 10์›” ๊ธฐ์ค€ ์•ฝ 30% ๊ฐ€๋Ÿ‰์˜ ์›น ์‚ฌ์ดํŠธ๋Š” HTTP/2 ๋ฅผ ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค)
'์ด ์–ด๋ ต๊ณ  ๊ท€์ฐฎ์€ Webpack ์„ค์ •์„ ์•ˆํ•ด๋„ ๊ดœ์ฐฎ์ง€ ์•Š์„๊นŒ?' ๋ผ๋Š” ์ƒ๊ฐ์ด ๋ฌธ๋“ ๋“ค์–ด์„œ ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค!

HTTP/1 & Webpack


Webpack์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค๋ช…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

Multiple Resources์— ๋Œ€ํ•œ HTTP Request Overhead๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋„๋ก
Single Resource๋กœ ๋งŒ๋“ค์–ด Request Overhead๋ฅผ ์ค„์ด๊ณ , ์„ฑ๋Šฅ ๊ฐœ์„ ์„ ๋„๋ชจํ•˜์ž.

HTTP/1 ์—์„œ ์‚ฌ์šฉ์ž๊ฐ€ ์›น ํŽ˜์ด์ง€์— ์ ‘๊ทผํ•  ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฆฌ์†Œ์Šค๊ฐ€ ํ•„์š”ํ•˜๋‹ค๊ณ  ๊ฐ€์ •ํ• ๊ฒŒ์š”

  1. HTML * 1
  2. Stylesheet * 2
  3. PNG * 10
  4. Script * 4

์œ„ ์ƒํ™ฉ์—์„œ๋Š” ์ตœ์ดˆ HTML ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜จ ๋’ค์—, ๋‚˜๋จธ์ง€ 16๊ฐœ(HTML ์ œ์™ธ)์˜ resources๋งŒํผ์˜ TCP ์—ฐ๊ฒฐ์ด ์ƒ๊น๋‹ˆ๋‹ค
(HTTP KEEP-ALIVE TCP์—ฐ๊ฒฐ์€ max ํ•œ๋„ ๋‚ด์—์„œ ๋Š๊ธฐ์ง€ ์•Š๊ณ  ๊ณ„์† ์ƒ์„ฑ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Œ)

KEEP-ALIVE์™€ ์ด๋ฅผ ํ™œ์šฉํ•œ ๋ณ‘๋ ฌ ์—ฐ๊ฒฐ์„ ํ•˜๋”๋ผ๋„,
๋ฆฌ์†Œ์Šค ์š”์ฒญ์— ๋Œ€ํ•ด Connection์ด ์—ฌ๋Ÿฌ๋ฒˆ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์€ ๋ง‰์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค
(๊ทธ๋ฆฌ๊ณ , ๋‹น์—ฐํ•˜๊ฒŒ๋„, ์ด ๋ถ€๋ถ„์—์„œ Request Overhead๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค)

๊ทธ๋ฆฌ๊ณ , ์ž‘์€ (๋˜๋Š” ํด ์ˆ˜๋„ ์žˆ๋Š”) ์—ฌ๋Ÿฟ์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ํ•˜๋‚˜๋กœ ๋ชจ์•„,
ํ•œ ๊ฐœ์˜(๋˜๋Š” ์ตœ์†Œํ•œ์˜) Resource๋งŒ Serving ํ•˜๊ธฐ ์œ„ํ•ด ๋งŒ๋“ค์–ด ์ง„ ๊ฒƒ์ด Webpack!

Webpack์˜ ์žฅ์ ์€, ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ bundlingํ•˜์—ฌ http connection์„ ์ตœ์†Œํ™” ํ•œ๋‹ค๋Š” ์ ์ด์ง€๋งŒ,
ํ•˜๋‚˜์˜ ์ž‘์€ ํŒŒ์ผ ๋ณ€๊ฒฝ์—๋„ (bundle.js์— ํฌํ•จ๋œ ํ•˜๋‚˜์˜ cssํŒŒ์ผ์ด ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค ํ•˜๋”๋ผ๋„)
์ „์ฒด๋ฅผ ๋‹ค์‹œ bundling ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, bundle.js๋ผ๋Š” ํฐ ํŒŒ์ผ์— ๋Œ€ํ•œ ์บ์‹ฑ์ด ์–ด๋ ต์Šต๋‹ˆ๋‹ค.

http connection๊ณผ ์บ์‹ฑ์˜ trade-off์—์„œ, connection ์ตœ์†Œํ™”์— ๋” ๋งŽ์€ ์„ฑ๋Šฅ ๊ฐœ์„ ์ด ์žˆ๊ธฐ๋•Œ๋ฌธ์—
HTTP/1 ์—์„œ webpack์„ ํ†ตํ•œ bundling์„ ํ•˜๋Š” ์ด์œ ๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๊ฒ ์Šต๋‹ˆ๋‹ค

๊ทธ๋Ÿผ HTTP/2 ํ™˜๊ฒฝ์—์„œ๋Š” ์–ด๋–จ๊นŒ์š”?

HTTP/2 ๋Š” Multiplexed Streams ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ, ํ•˜๋‚˜์˜ TCP Connection์œผ๋กœ ์—ฌ๋Ÿฌ ์š”์ฒญ์„ ์ฃผ๊ณ  ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
ํ•œ ๋ฒˆ์˜ ์š”์ฒญ์— ์—ฌ๋Ÿฌ ์ข…๋ฅ˜์˜ resource ์š”์ฒญ์— ๋Œ€ํ•œ stream frame์„ ์ƒ์„ฑํ•˜์—ฌ ์ฃผ๊ณ  ๋ฐ›๋Š” ํ˜•์‹์ด๋ฏ€๋กœ,
Multiple resources๊ฐ€ ํ•„์š”ํ•œ ํ™˜๊ฒฝ์—์„œ๋„ RTT(Round trip time)๊ฐ€ ์ž์—ฐํžˆ ์ค„์–ด๋“ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค

์Œ ๊ทธ๋Ÿผ ๋” ์ด์ƒ ์›นํŒฉ์ด ํ•„์š”์—†์–ด์ง€๋Š” ๊ฑธ๊นŒ์š”?

HTTP/2 ์™€ ์›นํŒฉ


HTTP/2์˜ ํ•ต์‹ฌ ๋ชฉํ‘œ

HTTP/2์˜ ์ฃผ์š” ๋ชฉํ‘œ๋Š” ์ง€์—ฐ ์‹œ๊ฐ„์„ ์ค„์ด๋Š” ๊ฒƒ์ด๋ฉฐ ์ด๋ฅผ ์œ„ํ•ด ์ „์ฒด ์š”์ฒญ ๋ฐ ์‘๋‹ต ๋‹ค์ค‘ํ™”๋ฅผ ์ง€์›ํ•˜๊ณ , HTTP ํ—ค๋” ํ•„๋“œ์˜ ํšจ์œจ์  ์••์ถ•์„ ํ†ตํ•ด ํ”„๋กœํ† ์ฝœ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ์ตœ์†Œํ™”ํ•˜๊ณ , ์š”์ฒญ ์šฐ์„ ์ˆœ์œ„ ์ง€์ • ๋ฐ ์„œ๋ฒ„ ํ‘ธ์‹œ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์š”๊ตฌ์‚ฌํ•ญ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์–‘ํ•œ ํ”„๋กœํ† ์ฝœ ๊ฐœ์„ ์‚ฌํ•ญ(์˜ˆ: ์ƒˆ๋กœ์šด ํ๋ฆ„ ์ œ์–ด, ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๋ฐ ์—…๊ทธ๋ ˆ์ด๋“œ ๋ฉ”์ปค๋‹ˆ์ฆ˜)์ด ์ง€์›๋˜์ง€๋งŒ, ๋ฌด์—‡๋ณด๋‹ค ๋ชจ๋“  ์›น ๊ฐœ๋ฐœ์ž๋“ค์ด ์ดํ•ดํ•˜๊ณ  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ํ™œ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฒƒ๋“ค์€ ๋ฐ”๋กœ ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ๋“ค์ž…๋‹ˆ๋‹ค.
์ถœ์ฒ˜: developers.google.com Web Fundamentals HTTP/2 ์†Œ๊ฐœ

์š”์ฒญ ๋ฐ ์‘๋‹ต ๋‹ค์ค‘ํ™”๊ฐ€ ๋œ๋‹ค๋ฉด, ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ๋ฒˆ๋“ค๋ง์„ ๋„์™€์ฃผ๋Š” Webpack์€
(๋ฌผ๋ก  Webpack ์€ ๊ทธ ์™ธ์—๋„, code splitting, Tree shaking ๋“ฑ ๋‹ค์–‘ํ•œ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค)
HTTP/2 ์„ธ์ƒ์ด ๋„๋ž˜ํ•˜๋Š” ์ˆœ๊ฐ„ Webpack์€ ํ•„์š” ์—†์–ด์ง€๋Š”๊ฒŒ ์•„๋‹๊นŒ์š”?

๊ฒฐ๋ก ์ ์œผ๋กœ๋Š”, HTTP/2 ์—์„œ๋„ bundle๋œ ํ•˜๋‚˜์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ์š”์ฒญํ•˜๋Š” ๊ฒƒ์ด ์„ฑ๋Šฅ ํ–ฅ์ƒ์— ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค

์ข€ ๋” ๋ช…ํ™•ํžˆ ํ•˜์ž๋ฉด, HTTP/1 ์‹œ์ ˆ๊ณผ ๊ฐ™์ด ํ•˜๋‚˜์˜ ํฐ bundleํŒŒ์ผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ๋ณด๋‹ค๋Š”
Grouping๋œ ์—ฌ๋Ÿฟ์˜ ์ž‘์€ bundles๊ฐ€ ๋” ํšจ๊ณผ์ ์ผ ๊ฒƒ ์ž…๋‹ˆ๋‹ค. (Benchmark ํ…Œ์ŠคํŠธ์— ๊ทผ๊ฑฐ)

๋”๋ถˆ์–ด Grouping๋œ ์—ฌ๋Ÿฟ์˜ ์ž‘์€ bundle ํŒŒ์ผ๋“ค์€ ์บ์‹ฑ์—๋„ ๋”์šฑ ํšจ๊ณผ์ ์ž…๋‹ˆ๋‹ค.
(์ž‘์€ ํ•˜๋‚˜๊ฐ€ ๋ณ€๊ฒฝ๋œ๋‹ค๊ณ  ํฐ ํ•˜๋‚˜๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ํ•„์š”๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค)

์˜ˆ์ƒ๊ณผ ๋‹ฌ๋ฆฌ, Multiplexed Stream์˜ ์ œํ•œ๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— (Nginx ์„ค์ •๋„ ์žˆ๋‹ค!)
"HTTP/2 ์—์„œ๋Š” ๋‹ค์ค‘ ์š”์ฒญ์ด ๊ฐ€๋Šฅํ•˜๋‹ˆ๊นŒ, bundle์ด ํ•„์š”์—†๊ฒ ๋‹ค "
๋ผ๊ณ  ๋‹จ์ˆœํ•˜๊ฒŒ ์ƒ๊ฐํ–ˆ๋˜ ๊ฒƒ๊ณผ๋Š” ๊ฒฐ๊ณผ๊ฐ€ ๋‹ฌ๋ผ ์˜์™ธ์˜€์Šต๋‹ˆ๋‹ค

๊ทธ๋ฆฌ๊ณ  Webpack์—์„œ๋Š” HTTP/2 ํ™˜๊ฒฝ์— ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋‚ด์žฅ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”
webpack.optimize.AggressiveSplittingPlugin ์„ ์‚ฌ์šฉํ•˜๋ฉด,
๊ธฐ์กด๊ณผ ๋‹ฌ๋ฆฌ, ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ž‘์€ chunk๊ฐ€ ์ƒ์„ฑ๋˜์–ด, caching์ด ๊ฐœ์„ ๋œ๋‹ค๊ณ  ๊ฐ€์ด๋“œํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค

๋งˆ์น˜๋ฉฐ


์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์–ธ์ œ๋‚˜ ์ž˜๋ชป๋œ ์ •๋ณด์— ๋Œ€ํ•œ ์ง€์  ๊ฐ์‚ฌํžˆ ๋ฐ›๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
์ €๋Š” ๊ถ๊ธˆ์ฆ์„ ํ’€์—ˆ์œผ๋‹ˆ ๋‹ค์‹œ webpack.config.js ๋ฅผ ๋งˆ์ € ์ž‘์„ฑํ•˜๋Ÿฌ ๊ฐ€์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜ต

References


  1. http2 does not need webpack
  2. https://medium.com/@asyncmax/the-right-way-to-bundle-your-assets-for-faster-sites-over-http-2-437c37efe3ff
  3. https://www.slideshare.net/eungjun/http2-40582114
  4. Webpack Github Issue for http2 support suggestions
  5. https://www.youtube.com/watch?v=UNMkLHzofQI
profile
Espresso Cream Cat DD
post-custom-banner

3๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2018๋…„ 10์›” 21์ผ

์ข‹์€ ํฌ์ŠคํŠธ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

1๊ฐœ์˜ ๋‹ต๊ธ€
comment-user-thumbnail
2018๋…„ 11์›” 27์ผ

http2๋ฅผ ์กฐ๊ธˆ์”ฉ ์ค€๋น„๋ฅผ ํ•˜๋˜ ์ค‘์— ์ข‹์€๊ธ€์„ ๋งŒ๋‚ฌ๋„ค์š”!

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ