Navigator.sendBeacon() is great method in JavaScript

The navigator.sendBeacon() method lets you send small bits of data to a web server asynchronously and handle the response. This is a great feature for mobile web developers because it allows you to handle push notifications without blocking your app’s main thread. The sendBeacon() method can send a maximum of 1024 bytes of data, and the data is sent in the HTTP POST request body.

A blog post that talks about the usefulness of the Navigator.sendBeacon() method in JavaScript. Find the example code snippet.


document.addEventListener('visibilitychange', function logData() {
	if (document.visibilityState === 'hidden') {
		navigator.sendBeacon('/log', analyticsData);

For more detail about Navigator.sendBeacon() please visit this website link

Latest posts by W3TWEAKS (see all)