Curriculum Series

What is the Beacon API?

What is the Beacon API?

What is the Beacon API?

Performance

Beacon 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
javascript
navigator.sendBeacon(url);
navigator.sendBeacon(url, data);

Example

javascript
navigator.sendBeacon('/analytics', {
event: 'page_view',
url: window.location.href,
});

Finished reading?

Mark this topic as solved to track your progress.