Skip to content
BENIBIX Learn

Virtual DOM vs DOM

People think the virtual DOM is a faster DOM that the browser has, and it is not. The DOM is the real page the browser draws. The virtual DOM is a copy a library like React keeps in memory. The library compares two copies and then changes the real DOM as little as it can.

Development🌐 Web Development

Virtual DOM

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

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.

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.
Full entry
Development🌐 Web Development

Document Object Model (DOM)

The browser's live tree of a page. JavaScript can read it and change it.

The DOM is the browser's live copy of a web page, held as a tree of parts. When a page loads, the browser turns the HTML into this tree. JavaScript can then find any part, change its text, add new parts or remove old ones. The page on screen updates to match. Every interactive web page works by changing the DOM.

Example
When Lucy adds a mug to her cart, JavaScript finds the cart count in the DOM and changes it from 2 to 3.
Why it matters
Every click that changes a page without reloading it goes through the DOM.
Full entry

In one line

Virtual DOM
A copy of the page kept in memory. The app checks two copies and fixes only what changed.
Document Object Model (DOM)
The browser's live tree of a page. JavaScript can read it and change it.