4 solutions for uploading monitoring data on the front end when the page is closed


This article focuses on the solution of how to upload monitoring data to the server when the page instance is closed with the business scenario of “front-end monitoring and reporting data” .

Among them, four schemes are involved, namely:

  • Synchronous XMLHttpRequest
  • img.src
  • navigator.sendBeacon
  • fetch keepalive

Synchronous XMLHttpRequest

 const data = JSON . stringify ({ time : performance. now () }); var xhr = new XMLHttpRequest (); // 第三个参数false,表示当前请求是同步xhr. open ( 'post' , 'http://api.wangxiaokai.vip/test'

The post 4 solutions for front-end uploading monitoring data when the page is closed first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9421
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment