<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<title>Blocking Script Demo</title>
<!-- CSS는 다운로드/파싱이 지연되면 CSSOM이 늦어져 render tree가 늦어짐 -->
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<h1 id="title">안녕하세요</h1>
<!-- ✅ 비차단: defer는 DOM 파싱 완료 후 실행 -->
<script defer src="./deferred.js"></script>
<!-- ✅ 블로킹: HTML 파싱이 여기서 멈춤 -->
<script>
const start = performance.now();
// 파싱 차단을 체감하기 위해 일부러 바쁜 작업
const endTime = performance.now() + 100; // 100ms busy-wait
while (performance.now() < endTime) {}
console.log('blocking script done in', performance.now() - start, 'ms');
</script>
<p>이 문장은 스크립트 실행이 끝난 뒤에야 파싱됩니다.</p>
</body>
</html>
확인 방법
포인트
display: none이 왜 빠질까?