The front-end monitors network changes and obtains network speed navigator.connection.downlink

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script>
	console.log('是否在线',navigator.onLine)
	console.log('网速',navigator.connection.downlink,'MB/s')
	window.addEventListener("online", () => {
     
     
      console.log('网络已连接')
    });
    window.addEventListener("offline", () => {
     
     
      console.log('网络已断开')
    });
	</script>	
</body>
</html>

Insert picture description here
This network speed test shows a big difference and can only be used as a reference value
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_35958891/article/details/108052167