How to detect internet speed in JavaScript?

前端 未结 9 1594
萌比男神i
萌比男神i 2020-11-22 01:56

How can I create a JavaScript page that will detect the user’s internet speed and show it on the page? Something like “your internet speed is ??/?? Kb/s”.

9条回答
  •  耶瑟儿~
    2020-11-22 02:49

    Well, this is 2017 so you now have Network Information API (albeit with a limited support across browsers as of now) to get some sort of estimate downlink speed information:

    navigator.connection.downlink
    

    This is effective bandwidth estimate in Mbits per sec. The browser makes this estimate from recently observed application layer throughput across recently active connections. Needless to say, the biggest advantage of this approach is that you need not download any content just for bandwidth/ speed calculation.

    You can look at this and a couple of other related attributes here

    Due to it's limited support and different implementations across browsers (as of Nov 2017), would strongly recommend read this in detail

提交回复
热议问题