JavaScript
JavaScript
Jul 19, 2025 · Frontend Development

How to Reliably Send Data When Users Close a Page: sendBeacon vs fetch keepalive

This article explains why traditional fetch or XMLHttpRequest calls often fail during page unload, and demonstrates two modern browser APIs—navigator.sendBeacon and fetch with keepalive:true—that reliably transmit analytics or draft data without blocking the user experience.

JavaScriptWeb APIfetch keepalive
0 likes · 7 min read
How to Reliably Send Data When Users Close a Page: sendBeacon vs fetch keepalive