Performance: Variables and dynamic content
MEDIUM IMPACT
This affects how quickly dynamic content updates appear and how much the page layout shifts during updates.
const outputElement = document.getElementById('output');
const content = fetchData();
outputElement.textContent = content;
// Updates only text node without changing layout sizeconst content = fetchData();
document.getElementById('output').innerHTML = content;
// Updates entire container on every variable change| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Replacing entire container HTML on variable change | High (full subtree replaced) | Multiple reflows per update | High paint cost | [X] Bad |
| Updating only text content inside container | Low (text node updated) | No reflows | Low paint cost | [OK] Good |