What is the Beacon API?
PerformanceBeacon API
The Beacon API is used to send an asynchronous and non-blocking request to a web server. The request does not expect a response. Unlike requests made using XMLHttpRequest or the Fetch API, the browser guarantees to initiate beacon requests before the page is unloaded and to run them to completion.
- The data is sent Asynchronously
- The data is sent reliably
- It doesn't impact the loading of next page
navigator.sendBeacon(url);
navigator.sendBeacon(url, data);
Example
navigator.sendBeacon('/analytics', {
event: 'page_view',
url: window.location.href,
});
00:00