Sending HTTP Requests Reliably When a Page Unloads
Sometimes you need to send a log or save a quick state right when a user closes the tab or moves to another page. If you just call a normal fetch() or axios request, the browser often cancels the network call mid-flight as the page unloads. Using Navigator.sendBeacon() Navigator.sendBeacon() is a browser API built to send small data reliably when a page is unloading. It hands the request off to the browser in the background, so it does not block the next page navigation while still finishing the request....