Are DOM Mutation Observers slower than DOM Mutation Events?

后端 未结 2 642
忘掉有多难
忘掉有多难 2021-02-03 12:07

The following code utilize DOM Mutation Event DOMNodeInserted to detect the existence of the body element and wrap its innerHTML into a wr

2条回答
  •  感情败类
    2021-02-03 12:34

    The simple answer is that mutation observers are asynchronous. They are sent whenever the engine feels like it, some time after the change has taken place and in some cases after a great many changes have taken place. That may be long after a DOM mutation event listener would have notified you, but meanwhile the engine has been free to get its work done without having to constantly create and bubble events for every piddling DOM change.

提交回复
热议问题