Pass signal from an AbortController into fetch. Calling abort() rejects that fetch (often with AbortError). Abort the previous controller before starting a new request so stale responses do not overwrite the UI.

Results appear here.

Start a load, then abort or start another.

Important JavaScript

let controller = null;

async function load(id) {
  if (controller) {
    controller.abort();
  }
  controller = new AbortController();
  const response = await fetch(url, { signal: controller.signal });
  // …
}