4 ms·
Thanks for pointing out the new MutationObserver API! I actually wasn't aware of that, so for exhaustive comparison I'd have to do more research into it. Readin
by OmarIsmail 14y ago
Thanks for pointing out the new MutationObserver API! I actually wasn't aware of that, so for exhaustive comparison I'd have to do more research into it. Reading up on the API there are a few issues that I see though:
1) You still have the same DOM structure brittleness. For detecting insertions you have to bind to a an ancestor node and monitor each change to see if the new nodes are of the type you're interested in - which is essentially through selectors/traversal.
2) with the CSS technique you can structure the selectors/animations to only trigger when the specific nodes come into existence. It's true that you have a callback on every animation fired, but that's a simple switch case that executes super fast. With MutationObserver you have to do a lot more processing on each callback, including interacting with the DOM to figure out which nodes were added/changed/deleted - and accessing the DOM is quite slow. I think you'll have to be really careful with these MutationObservers or you can run into situations where you do have a big performance hit.
- geuis 14y agoInteresting discussion Omar. I think combining the API with the css technique could lead to some interesting uses.