I'm going to answer my own question two years later according to the updated DOM spec from WHATWG.
As shown in the spec:
To queue a mutation observer compound microtask, run these steps:
- If mutation observer compound microtask queued flag is set, terminate these steps.
- Set mutation observer compound microtask queued flag.
- Queue a compound microtask to notify mutation observers.
While "Queuing a compound microtask" links to a section in the HTML spec explaining the microtask queue model.
Therefore, we can conclude that MutationObserver
callbacks are fired as microtasks, which are indeed sooner than the task queue tasks as suggested by the answer of @Scott Miles above.
For further understanding of the event loop and processing model, the Event Loop section of the HTML spec would be perfect.
Personally, I'm glad to see that MutationObserver
s are part of the standard and have a well-documented and consistent timing model. With MutationObserver
s supported in most modern browsers, I think they are solid for production use now.