Skip to content

coalesce

Eugene Lazutkin edited this page Jul 5, 2026 · 1 revision

Coalescing

Cross-tab in-flight dedup — the enhancement no page-side library can provide, because only the worker sees every tab's traffic.

import {createCoalescer} from 'double-meh-sw/coalesce.js';

const coalescer = createCoalescer();
const response = await coalescer.run(request, () => fetch(request));

run(request, fn) keys on method + URL + Accept. Concurrent callers — from any tab — share one upstream call; each receives its own response.clone(), so bodies never compete. Once the shared call settles, the key clears and the next request flies fresh.

Note the layering: the worker coalesces wire calls (bytes). A page library like double-meh additionally dedups at the decoded-envelope level (parse-once) — the two compose, they don't compete; decoded objects cannot cross the worker boundary at all (structured clone copies, never shares).

See also: The assembly.

Clone this wiki locally