On large sites, the term "js beacon" is often seen in response codes. And on the Internet, nothing really is written about it, except that it is akin to ajax. What is it generally beacon, technology or what and how it differs from the usual javascript? If possible, in simple words.

  • Notification server about anything. - user207618
  • And you can learn more about how it works and how it differs from the standard ajax? - Pavel Igorev
  • Read more here: w3c.imtqy.com/beacon - user207618
  • So there everything is in English. And you do not know? - Pavel Igorev

1 answer 1

  1. The request is made asynchronously, but without being tied to the current page. For example, if you started such a request, and the user closed the tab or moved to another page, then, unlike the usual AJAX request, your request will not be interrupted, and the user will not need to be forced to wait for it to end.

  2. Unlike regular AJAX, you will not receive a response to such a request. All you know is that the request is queued for sending to the server or not.

This type of request is ideal for sending some analytics when leaving the page. For example, you can record how long the user was on the page, what he did, and so on.

window.addEventListener('unload', function () { navigator.sendBeacon("/log", analyticsData); }, false); 

Surely you can think of a way to use these requests for something else, but since you can’t know if the request ended with an error or was successful, you will be severely limited. To receive new data from the server such requests are not suitable.

Finally, you cannot use these queries in IE and Safari . They do not work there. So for nothing but non-critical analytics, this kind of query is not yet suitable.

  • Do not quite understand. For example, I want the news block to be updated using the beacon technology. Well, the user closed the tab and what's next, what's the point, where will the answer be sent if the tab is closed? Or using it, you can only track how long the tab was open and what the user did with the news block? - Pavel Igorev
  • Just track down. Block some update will not work. You do not get a server response to such requests. - sanmai