1. 레이아웃 스레싱

1-1. 얼마나 시간이 차이가 날까?

image.png

1-2. 레이아웃 스레싱 방지

  1. DOM 읽기와 쓰기 작업을 분리하자.

    // 최적화된 코드
    const width = box.offsetWidth;
    const height = box.offsetHeight;
    
    box.style.width = width + 10 + 'px';
    box.style.height = height + 10 + 'px';
    
    
  2. requestAnimationFrame 활용

    requestAnimationFrame(() => {
      // 레이아웃 변경 작업
    });
    

1-3. 잠깐, 그러면 모든 렌더링을, requestAnimationFrame 에 맞춰야해?