THE BEACON API
To maximize the amount of information transmitted about a page, many analytics tools need to send telemetry or analytics data to a server as late in a page's lifecycle as possible. As a result, the optimal pattern is to send a network request on the browser's unload
event. This event signals that a page departure is occurring and that no more useful information will be generated on that page.
When an unload
event is fired, analytics tools want to cease collecting information and attempt to ship off what they have to the server. This presents a problem, as the unload
event means to the browser that there is little reason to dispatch any pending network requests (since the page is being discarded anyway). For example, any asynchronous requests created in an unload
handler will be cancelled by the browser. Therefore, an asynchronous XMLHttpRequest
or fetch()
is unsuitable for this task. Analytics tools could use a synchronous XMLHttpRequest
to force delivery of the...