Performance: Textarea
LOW IMPACT
Textarea affects page load speed minimally but can impact rendering performance when resized or when content changes dynamically.
const textarea = document.querySelector('textarea');
textarea.addEventListener('input', () => {
requestAnimationFrame(() => {
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
});
});<textarea oninput="this.style.height='auto';this.style.height=this.scrollHeight+'px'"></textarea>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline oninput resizing | Minimal DOM ops | 1 reflow per keystroke | Moderate paint cost | [X] Bad |
| requestAnimationFrame batching | Minimal DOM ops | 1 reflow per frame (~16ms) | Lower paint cost | [OK] Good |