Langsung ke konten
Skillpedia
Website & UI (frontend)75k Β· #2820

dom-performance

Fungsinya

Skill ini mencari kode halaman yang terus membaca dan mengubah tata letak, yang memaksa perhitungan ulang yang lambat. Cocok untuk pengembang yang menginginkan halaman yang mulus dan responsif.

Kapan dipakai

  • βœ“Saat halaman membeku sejenak selama animasi atau pembaruan.
  • βœ“Saat skrip memperbarui banyak elemen di dalam loop.
  • βœ“Saat gulir atau sentuhan terasa lamban.

Link skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/dom-performance/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/dom-performance/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBisakah Anda memeriksa kode saya untuk langkah-langkah yang membuat halaman lambat diperbarui?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent menemukan tempat di mana pembacaan dan penulisan tata letak halaman bercampur. Agent menyarankan agar semua pembacaan dilakukan lebih dulu, lalu semua penulisan, dan menandai beberapa listener gulir sebagai passive.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Minimize costly DOM read/write operations

Every 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 β€” even with just 10 elements β€” 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.

Quick Reference

  • Never interleave DOM reads (offsetHeight, getBoundingClientRect) with DOM writes (style changes)
  • Batch all reads first, then all writes
  • Use requestAnimationFrame for visual updates
  • Use DocumentFragment or innerHTML for bulk DOM insertion
  • Avoid per-frame React state updates across many visible components when a simpler CSS or reduced-frequency approach would work
  • Use passive listeners for scroll, touch, and wheel when you do not call preventDefault

Check

Identify any layout thrashing in this code β€” 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.

Fix

Refactor 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.

Explain

Explain layout thrashing, what causes it, and how batching reads and writes prevents it.

Code Review

Review 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.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/dom-performance

Pertanyaan umum

Apa itu layout thrashing?

Itu terjadi ketika browser dipaksa menghitung ulang tata letak berulang kali dalam satu pembaruan, yang dapat membuat halaman membeku sebentar.

Apa itu listener passive?

Itu memberi tahu browser bahwa penangan gulir atau sentuhan tidak akan memblokir gulir, sehingga gulir tetap mulus.

Apakah ini mencakup pembaruan state React?

Skill mencatat bahwa pembaruan state berbasis frame yang berulang di banyak komponen dapat menjadi masalah kinerja jika terlihat di kode.

Detail

Deskripsi asli dari pembuat

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.

repo: thedaviddias/Front-End-Checklist

Popularitas

Bintang GitHub
75k
Peringkat
#2820
Lisensi
MIT
Diperbarui
31/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa