-
[JS] 문서의 로드 시점(onload, DOMContentLoaded)Javascript 2023. 4. 26. 21:05

onload
- 외부자원과 이미지 로드가 모두 끝났을때 발생
- 초기 렌더링 이전에 호출하고 싶을 때 사용
window.onload = () => { console.log('hello, world!'); };DOMContentLoaded
- DOM이 로드가 끝났을때 발생
- 초기 렌더링 이후에 호출하고 싶을 때 사용
- 초기 HTML 문서를 완전히 불러오고 분석했을 때 발생
- 스타일 시트, 이미지, 하위 프레임의 로딩은 기다리지 않는다.
window.addEventListener('DOMContentLoaded', (event) => { console.log('DOM fully loaded and parsed'); });'Javascript' 카테고리의 다른 글
[JS] throttle & debounce (0) 2023.04.29 [JS] querySelector과 querySelectorAll (0) 2023.04.28 [JS] json-server로 pagination 구현하기 (0) 2023.04.26 [JS] async / await (0) 2023.04.24 [JS] 클로저(Closure) (0) 2023.04.24