Skip to content
Graeme Yeates edited this page Jul 27, 2015 · 3 revisions

Why setTimeout polling to detect changes instead of using the DOM3 MutationEvents?

First off, a well vetted DOM3 MutationObserver shim exists (https://github.com/polymer/MutationObservers) and can be great for IE>9 (https://github.com/bitovi/mutationobserver is an attempt to consolidate some the shims, but doesn't include this one). However, DOM3 come with some significant disadvantages:

i. Its a deprecated API; several browsers (e.g. some versions of Phantom, etc.) don't implenent some or all the features of it
ii. Some browsers which use the event anywhere enter slow state for the entire DOM
iii. It cannot support arbitary DOM: moving forward I'm considerring implementing MOs on virtual dom or idom.
iv. It cannot capture all the MutationEvents the MutationObserver supports

However, there are a number of disadvantages as well - namely, performant polling requires making some tradeoffs; may miss some changes; and may identify the wrong changeset if the DOM changes like crazy

Both shims can be quite well suited different use cases depending on: observed vs non observed DOM size, types of events being observed, and types of DOM thrashing occurring.

Clone this wiki locally