async defer - amorfati0310/javascript-vm GitHub Wiki
javascript์ฝ๋๋ฅผ src๋ก ์ง์ ํ๊ณ ์๋ script ํ๊ทธ์ ์์น๋ ๋ณดํต body ํ๊ทธ๊ฐ ๋ซํ๊ธฐ ์ ์ ์์น์ํจ๋ค. ๊ทธ๋์ผ DOMํ์ฑ์ ๋ฐฉํดํ์ง ์๋๋ค. ํ์ง๋ง scriptํ๊ทธ์๋ async ์ defer๋ผ๋ ์์ฑ์ด ์๋ค. ์ด๋ฅผ ์ด์ฉํ๋ฉด DOM ๋ก๋ฉ์ ๋ฐฉํดํ์ง ์๊ณ , javascript ๋ฅผ ๋ค์ด๋ก๋ ๋ฐ๊ณ ์คํํ ์ ์๋ค.
์ด์ ๊ด๋ จ๋ ์๋ ๊ธ์ ํ์ตํ๋ค. http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html
์ด๊ธ์ ๋์จ๊ฒ์ฒ๋ผ, script์ dom ๋ค์ด๋ก๋์ ํ์ฑ์ ์์์ ๋ณ๋ ฌ์ฒ๋ฆฌ๋ฐฉ๋ฒ์, async์ defer ์์ฑ์ ํตํด์ ์ ํ์ ์ผ๋ก ์ฌ์ฉํ ์ ์๋ค. ์ด๋ฅผ ์ ํ์ฉํด์ scriptํ๊ทธ๋ฅผ HTML์์ ์์น์ํฌ ์ ์๋ค.
async
async๋ ๋์์ htmlํ์ฑ๊ณผ ๋์์ ๋ค์ด๋ก๋๋ฅผ ํ๋ค๊ฐ script๊ฐ ์คํ๋ ๋๋ htmlํ์ฑ์ด ์ ์ ๋ฉ์ถฅ๋๋ค. async downloads the file during HTML parsing and will pause the HTML parser to execute it when it has finished downloading.
defer
defer๋ ๋ค์ด๋ก๋๋ ์ญ์ ๋์์ ์งํ๋๊ณ ์คํ ์์ฒด๋ฅผ htmlํ์ฑ์ด ๋ค ๋๋๋ค์ ์งํํฉ๋๋ค
defer downloads the file during HTML parsing and will only execute it after the parser has completed. defer scripts are also guaranteed to execute in the order that they appear in the document.