{"data":{"slug":"github-thedaviddias-front-end-checklist-skills-dom-performance-81f015e4bda2","title":"Optimize DOM Read\/Write Operations for Performance","summary":"Refactor code to batch DOM reads before writes and use requestAnimationFrame to avoid layout thrashing and improve browser performance. This includes marking passive listeners and using DocumentFragment for bulk DOM insertion.","url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-dom-performance-81f015e4bda2","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-thedaviddias-front-end-checklist-skills-dom-performance-81f015e4bda2","markdown_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-dom-performance-81f015e4bda2.md","download_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-dom-performance-81f015e4bda2\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Ensure that no DOM reads (e.g., offsetHeight, getBoundingClientRect) are interleaved with writes (e.g., style changes). Before making changes, validate that the code is not using per-frame React state updates across many visible components. The first deliverable should be a list of layout thrashing issues identified in the code, formatted as a report with specific line numbers and suggestions for batching reads and writes.","instructions":"---\nname: dom-performance\ndescription: \"Use when reviewing scripts, client components, bundles, or runtime behavior related to Minimize costly DOM read\/write operations. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug. In React, repeated requestAnimationFrame-driven state updates across multiple mounted components are a valid performance smell when visible in the source.\"\nmetadata:\n  category: javascript\n  priority: high\n  difficulty: intermediate\n  estimatedTime: \"20\"\n  source: frontendchecklist.io\n  url: https:\/\/frontendchecklist.io\/rules\/javascript\/dom-performance\n---\n\n# Minimize costly DOM read\/write operations\n\nEvery time you read a layout property after making a DOM change, the browser must synchronously recalculate layout (reflow) before returning the value. Doing this in a loop \u2014 even with just 10 elements \u2014 can freeze the page for hundreds of milliseconds. This is called layout thrashing and is one of the most common causes of janky animations and slow renders.\n\n## Quick Reference\n\n- Never interleave DOM reads (offsetHeight, getBoundingClientRect) with DOM writes (style changes)\n- Batch all reads first, then all writes\n- Use requestAnimationFrame for visual updates\n- Use DocumentFragment or innerHTML for bulk DOM insertion\n- Avoid per-frame React state updates across many visible components when a simpler CSS or reduced-frequency approach would work\n- Use passive listeners for scroll, touch, and wheel when you do not call preventDefault\n\n## Check\n\nIdentify any layout thrashing in this code \u2014 places where DOM reads and writes are interleaved in loops. Also flag scroll, touch, and wheel listeners that should be passive to avoid blocking the main thread.\n\n## Fix\n\nRefactor this code to batch all DOM reads before writes, eliminating forced synchronous layouts. Mark relevant listeners as passive when they do not need to cancel scrolling.\n\n## Explain\n\nExplain layout thrashing, what causes it, and how batching reads and writes prevents it.\n\n## Code Review\n\nReview scripts, client components, and browser execution paths related to Minimize costly DOM read\/write operations. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.\n\n---\n\nFor full implementation details, code examples, and framework-specific guidance,\nsee `references\/rule.md`.\n\nRule page: https:\/\/frontendchecklist.io\/rules\/javascript\/dom-performance\n","use_cases":["Reviewing React components with frequent state updates that cause layout thrashing","Optimizing scroll and touch events to avoid blocking the main thread","Refactoring code to batch DOM operations and reduce layout thrashing"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/thedaviddias\/Front-End-Checklist\/blob\/e8d14d049010e2ce25afcd5e8609dfcbbe63e47e\/skills\/dom-performance\/SKILL.md","source_commit":"e8d14d049010e2ce25afcd5e8609dfcbbe63e47e","license":null,"version":null,"listing_approved_at":"2026-11-23","created_at":"2026-11-22T15:55:22.000000Z","updated_at":"2026-11-23T04:54:56.000000Z","seo_title":"Optimize DOM Read Write Operations for Performance","seo_description":"Improve browser performance by minimizing costly DOM read\/write operations. Learn how to batch reads, use requestAnimationFrame, and mark passive listeners.","seo_keywords":["optimize DOM performance","reduce layout thrashing","batch DOM operations","passive event listeners","requestAnimationFrame","DOM read write optimization"]}}