Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrdtbs/8e31f6aed9f785f555a2410ecffd5ab2 to your computer and use it in GitHub Desktop.
Save hrdtbs/8e31f6aed9f785f555a2410ecffd5ab2 to your computer and use it in GitHub Desktop.
DOM操作はブラウザの負担になる説

DOM操作はブラウザの負担になる?

  • DOM操作後に行われるレイアウト処理が重く時間がかかる場合がある
    • DOM操作自体は大して重くない
  • レイアウトの強制同期により著しくパフォーマンスが低下する場合がある
    • DOM操作などの実行中にレイアウト処理が何度も走りパフォーマンスが低下する
    • DOM操作後にレイアウト情報を参照するようなコードを書いていると,最新のレイアウト情報を参照しようとして起きる
      • 再レンダリング後に呼び出されるrequestAnimationFrameを使ったり、DOM操作前にレイアウト情報を参照するようなコードを書く
      • offsetLeft, getBoundingClientRect(), scrollTo(), scrollTop, focus(), select(), window.getComputedStyle()辺り
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment