Network Information API
Fast forward 12 years, and after many attempts over the years by developers to test network speeds, there is a new Network Information API by the WICG: “The Network Information API enables web applications to access information about the network connection in use by the device.” The proposal introduces a few simple APIs:
navigator.connection.type– the type of connection, which can be bluetooth, cellular, ethernet, mixed, none, other, unknown, wifi, or wimax
navigator.connection.effectiveConnectionType– a measure of how fast the connection is, which can be 2g, 3g, 4g, or slow-2g
downlinkMax– upper bound on the downlink speed of the first network hop in megabits per second
downlink– the effective bandwidth estimate in megabits per second, based on recently observed application layer throughput
rtt– effective round-trip time estimate in milliseconds based on recently observed application-layer RTT measurements
saveData– true if the user requests a reduced data usage mode
Browser Support and Use Cases
Full support for the Network Information API exists in Chrome for Android (78+), Firefox for Android (68+), and Samsung Internet (10.1+). Partial desktop browser support exists on Chrome 79+ and Edge 76+. There are many possible use cases for the Network Information API. For example, bandwidth consumption could get reduced over slow or cellular networks, assets could get cached differently via service workers, and an offline connection might get assumed if the connection speed is so slow that it’s effectively the same as being offline.
While it has taken more than a decade since the first iPhone was released to get this API, this is an exciting proposal to watch as it will hopefully allow applications to deliver streamlined options for slower internet connections, and allow users to request smaller data requests when their bandwidth is limited or metered. If you need help creating highly performant applications or leveraging emerging APIs and best practices, please contact us to discuss how we can help!