Skip to content
BENIBIX Learn

Virtual DOM

Development🌐 Web DevelopmentFrameworks

Also known as VDOM, Virtual Document Object Model, DOM Diffing

A copy of the page kept in memory. The app checks two copies and fixes only what changed.

Think of it like

It is like checking a new list with the old one. Then you fix just the lines that changed.

Example

Lucy's list has 500 rows, and one price changes. The virtual DOM finds that one change, so only one line on the page is redrawn.

Why it matters

You can write code as if the whole page is redrawn each time. The library does the careful, small updates for you.

Definition

A virtual DOM is a light copy of the page that a UI library keeps in memory. When data changes, the library builds a new copy. It compares the new copy with the old one to find what is different. Then it changes only those parts of the real page. Changing the real page is slow, so doing it less keeps the app fast. React and Vue both work this way.
Two virtual trees are compared, and only the one change reaches the page.

Common mistake

Thinking it makes every app fast. It saves work on the real page, but the comparing has a cost of its own.

Key takeaways

  1. 1
    A copy in memory. Light to build and to compare.
  2. 2
    Compare, then patch. Only the changes reach the page.
  3. 3
    You write simply. The library handles the updates.

Compare