Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repaint์™€ reflow #9

Open
BKJang opened this issue May 25, 2019 · 2 comments
Open

repaint์™€ reflow #9

BKJang opened this issue May 25, 2019 · 2 comments
Labels
Advance of JS It is related to advance of JS.

Comments

@BKJang BKJang added the Advance of JS It is related to advance of JS. label May 25, 2019
@BKJang
Copy link
Owner Author

BKJang commented May 25, 2019

repaint์™€ reflow

rendering

์œ„์˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋ธŒ๋ผ์šฐ์ €๋Š” ํ™”๋ฉด์„ renderingํ•˜๋Š” ๊ณผ์ •์—์„œ ๋ฐฐ์น˜(flow) ์™€ ๊ทธ๋ฆฌ๊ธฐ(paint) ์˜ ๊ณผ์ •์„ ๊ฑฐ์นœ๋‹ค.

์ƒ์„ฑ๋œ DOM ๋…ธ๋“œ์˜ ๋ ˆ์ด์•„์›ƒ์ด ๋ณ€๊ฒฝ๋  ๋–„, ๋ณ€๊ฒฝ ํ›„ ์˜ํ–ฅ์„ ๋ฐ›๋Š” ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ๋‹ค์‹œ ๊ณ„์‚ฐํ•˜๊ณ  ๋ Œ๋” ํŠธ๋ฆฌ๋ฅผ ์žฌ์ƒ์„ฑ ํ•œ๋‹ค.
์ด๋Ÿฌํ•œ ๊ณผ์ •์„ reflow๋ผ ํ•˜๊ณ  reflow๊ฐ€ ์ผ์–ด๋‚œ ํ›„, repaint๊ฐ€ ์ผ์–ด๋‚œ๋‹ค.

์ฆ‰, DOM์˜ ๋…ธ๋“œ๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ ๋งˆ๋‹ค DOM tree๋ผ๋Š” ์ž๋ฃŒ๊ตฌ์กฐ์— ์ ‘๊ทผํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— DOM์˜ ๋ ˆ์ด์•„์›ƒ์„ ๋ณ€๊ฒฝํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ๋Š” ์ด๋ฅผ ์ตœ์ ํ™”ํ•˜๊ธฐ ์œ„ํ•œ ๊ณ ๋ฏผ์ด ํ•„์š”ํ•˜๋‹ค.

reflow

function reFlow() {
    var container = document.getElementById('container');

    container.appendChild(document.createTextNode('hello'));
}

์œ„์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด conatiner๋ผ๋Š” ์—˜๋ฆฌ๋จผํŠธ์— hello๋ผ๋Š” TextNode๋ฅผ ์ถ”๊ฐ€ํ–ˆ๋‹ค. ์ด๋กœ ์ธํ•ด DOM ๋…ธ๋“œ์˜ ๋ ˆ์ด์•„์›ƒ์ด ๋ฐ”๋€Œ๋ฉฐ reflow์™€ repaint๊ฐ€ ์ผ์–ด๋‚  ๊ฒƒ์ด๋‹ค.

repaint

function repaint() {
    var container = document.getElementById('container');

    container.style.backgroundColor = 'black';
    container.style.color = 'white';
}

์œ„์˜ ์ฝ”๋“œ์—์„œ๋Š” ์ด์ „์˜ ์ฝ”๋“œ์™€ ๋‹ค๋ฅด๊ฒŒ ์—˜๋ฆฌ๋จผํŠธ์˜ style๋งŒ ๋ณ€๊ฒฝํ–ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ DOM ๋…ธ๋“œ์˜ ๋ ˆ์ด์•„์›ƒ์€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์•˜๊ณ  style์†์„ฑ๋งŒ ๋ณ€๊ฒฝ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— reflow๋Š” ์ผ์–ด๋‚˜์ง€ ์•Š๊ณ  repaint๋งŒ ์ผ์–ด๋‚˜๊ฒŒ ๋œ๋‹ค.

reflow์™€ repaint๊ฐ€ ๋งŽ์•„์งˆ์ˆ˜๋ก ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ Œ๋”๋ง ์„ฑ๋Šฅ์€ ๋Š๋ ค์ง€๊ฒŒ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ์ค„์ผ ์ˆ˜๋ก ์„ฑ๋Šฅ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.

@BKJang
Copy link
Owner Author

BKJang commented May 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Advance of JS It is related to advance of JS.
Projects
None yet
Development

No branches or pull requests

1 participant