Need a deeper understanding of how a Virtual DOM is different from a real DOM

4

As all articles say the Virtual DOM is lightweight and allows us to update only those nodes that has to be updated, unlike the real DOM that updates the whole nodes structure.

So the first question: how is Virtual DOM lightweight? Since it can’t affect the nodes structure I assume VDOM does not have some methods that the real one has (like .createElement). If I’m wrong then what make the VDOM lightweight?

Second question: how does VDOM make the real DOM update only necessary elements? Why does DOM not do that itself? Since VDOM can’t affect the nodes structure it will eventually ask the real DOM do all the necessary updates.
If the real DOM is able to update only necessary parts of the whole structure then why do we need the VDOM? Why isn’t it a built-in DOM behaviour?

Some articles say that the VDOM accumulates updates and then rerender the whole DOM at once. While the real DOM updates the whole nodes structure right away everytime something changes the structure. So VDOM would change 5 element in one update while real DOM would need 5 updates to change 5 elements.
If VDOM works like this then why does it traverse the whole structure and tag nodes that has to be updtaed? Why not just wait until there is no more changes to the structure and just update the whole DOM? Not traversing and tagging nodes?

Would really appreciate if you explain this to me in details or give me some links to in-depth articles/videos on this topic.

6

2

Virtual DOM solves the problem of aggressive re-rendering. Newer frameworks know how to know which state changes are relevant to which DOM nodes, making the Virtual DOM approach redundant.


Before React & Friends, popular frameworks and libraries were very stateful and object-oriented. From jQuery to Ext.js, and the likes. Working with those was very problematic in many ways:

  • State propagation was very error-prone, because you had to do it manually. (The framework only cared about giving you a zoo of components.)
  • State was all over the place. Not as in “oh no, derived state here and there”, but as in “there is state in every little crevice of my SPA”. Debugging and refactoring that was hell (by modern standards).
  • Some state was embedded into the DOM. (If you want a value of the checkbox component, you had to ask it by calling a method, and that would in turn ask the DOM. Ew.)

When React & Friends entered the industry, they streamlined the state management and decoupled the state from the DOM, making the aforementioned issues almost extinct.

In one part that was achieved with aggressive immutability: when framework detects a state change, it redraws the entire component tree. Such an approach can cause a colossal performance hit from all the relayout and repaint.

The concept of the Virtual DOM was introduced to solve that repaint issue. The framework will render everything into a pocket dimension, and then check the difference with the real DOM. The latter will be precisely hammered until it matches the Virtual DOM. But because the Virtual DOM is not inserted into document, it will not trigger any kind of visual recalculation.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật