# IntersectionObserver and Asynchronous Visibility vs MutationObserver and Batched Microtask Delivery

- **Canonical URL:** https://frontend.rocks/vs/intersection-observer-vs-mutation-observer/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** MutationObserver tracks DOM tree/attribute edits as microtasks; IntersectionObserver tracks post-layout geometry.

## Comparison Matrix

| Dimension | IntersectionObserver and Asynchronous Visibility | MutationObserver and Batched Microtask Delivery |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Baseline · Widely |
| **Domain** | DOM & Events | DOM & Events |
| **Mental Model** | Eliminate scroll-handler layout thrashing in lazy loading and infinite lists—IntersectionObserver reads cached layout boxes once per frame after Layout. | Replace main-thread-freezing Mutation Events with batched microtask delivery—MutationObserver queues DOM edits silently and flushes MutationRecord[] once after the Call Stack unwinds. |
| **Prerequisites** | Browser Rendering Pipeline (Critical Rendering Path) (IntersectionObserver computes intersections once per frame immediately after the Layout phase.); Layout Thrashing (Forced Synchronous Layout) (Replaces scroll-handler getBoundingClientRect() polling that forces synchronous layout recalculation.) | Event Loop, Macrotasks, and Microtask Queue (MutationObserver callbacks execute during the Microtask Checkpoint before Update the Rendering.) |
| **When Not to Use** | When not to use IntersectionObserver: Never use it for continuous pixel-by-pixel parallax or scroll-linked animations, use CSS animation-timeline: scroll() or view(). | When not to use MutationObserver: Never use MutationObserver to detect element size or viewport visibility, use ResizeObserver or IntersectionObserver. |

## IntersectionObserver and Asynchronous Visibility — Under the Hood
Blink evaluates `IntersectionObserver` registrations during `Update the Rendering` immediately after Layout, reusing already-computed box geometry instead of forcing synchronous `getBoundingClientRect()` reflows. Like a warehouse guard checking monitors once after each shift change, it fires callbacks only when `intersectionRatio` crosses a configured threshold.

1. **Post-Layout Hook**: During `Update the Rendering`, the engine reuses already-computed layout boxes to test intersections.
2. **Threshold Crossing**: Callbacks fire only when `intersectionRatio` crosses a configured threshold (not on every pixel scrolled).
3. **One Observer, Many Targets**: A single `IntersectionObserver` instance tracks thousands of elements more cheaply than one observer per component.

```js
const io = new IntersectionObserver(
  (entries) => {
    for (const entry of entries) {
      if (!entry.isIntersecting) continue;
      hydrateWidget(entry.target);
      io.unobserve(entry.target);
    }
  },
  { rootMargin: '200px 0px', threshold: 0.01 }
);
```

## MutationObserver and Batched Microtask Delivery — Under the Hood
Blink appends DOM insertions, removals, and attribute writes to an observer's `MutationRecord` queue synchronously without invoking JS, then schedules one [Microtask](/concepts/event-loop-tasks-microtasks) to flush the batch once the Call Stack empties. This prevents per-node callback thrashing.

1. **Silent Recording**: Each DOM write appends a `MutationRecord` to the observer's internal queue without pausing JS.
2. **Microtask Checkpoint**: When the Call Stack empties, the engine schedules one microtask carrying all queued records.
3. **Targeted Filtering**: Passing `attributeFilter: ['aria-expanded']` avoids waking JS for unrelated `style` or `class` churn.

```js
const mo = new MutationObserver((records) => {
  for (const r of records) {
    if (r.type === 'attributes') syncPanelState(r.target);
  }
});
mo.observe(panel, { attributes: true, attributeFilter: ['data-open'] });
```

## Interactive Labs & Dissections
- [IntersectionObserver and Asynchronous Visibility Lab](https://frontend.rocks/concepts/intersection-observer/#lab) ([Markdown](https://frontend.rocks/concepts/intersection-observer.md))
- [MutationObserver and Batched Microtask Delivery Lab](https://frontend.rocks/concepts/mutation-observer/#lab) ([Markdown](https://frontend.rocks/concepts/mutation-observer.md))

## Related Architecture Autopsies
- [Autopsy #02: Anatomy of a Memory Leak on an 8-Hour Dashboard](https://frontend.rocks/autopsies/eight-hour-spa-memory-leak/) ([Markdown](https://frontend.rocks/autopsies/eight-hour-spa-memory-leak.md)): SPA operations dashboard climbs from 120 MB to 2.4 GB RAM over an 8-hour shift and crashes with Aw, Snap!

## Primary Sources
- https://w3c.github.io/IntersectionObserver/
- https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
- https://dom.spec.whatwg.org/#mutation-observers
- https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
