Arrows up and down, wifi sign, accelerometer

Network Information API

If you have been around me for a while you might have noticed that I am a huge fan of Network Information API. I fell in love with it because I used to travel a lot, even before the Crazy year of 2016. On trains there isn’t usually fast internet and there are places where connection is pretty much non-existent. Here comes Network Information API to the rescue, sort of.

I am overly optimistic but this API has so many use cases even if mobile networks will get faster and have better coverage, there will still be places with slow internet. Think remote areas. Estonia1 is an exception, not a rule.

If this API gets implemented correctly and wise developers will use it, it’ll be helpful for a lot of users. Don’t get me wrong, I love JavaScript frameworks be it jQuery, Angular or Vue.js, but sometimes especially on mobile or on train I’d love to live without them. Network Information API could automatically detect slow connection and offer website rendered on web server instead of offering a link like GMail does it.

Another place where I would love to see this are video players which could give option to the user before attempting to play the content2. And my wildest dream is to expand  img  tag, so appropriately sized image will download but that’s a big stretch.

Where can I use it?

Well, at the moment it’s available only on Android, Android Browser, Chrome, Opera Mobile and Firefox, but you need to have the latest version of the browser(s). So at the moment it’s pretty much useless and with the adoption rate of new Android we’ll have to wait at least a year or two before we can use it more widely.

What does it do?

Enough, it tells you what kind of internet connection you have, how fast it is and adds an event in case your connection changes. I made a jsbin just for that:

JS Bin on jsbin.com

navigator.connection.type informs you about the connection type. According to the specification it can have values:

  • bluetooth
  • cellular
  • ethernet
  • none
  • wifi
  • wimax
  • other
  • mixed
  • unknown
navigator.connection.downlinkMax informs you how fast can you download in Megabits per second.

You can assign your own connection change function to the the event listener navigator.connection.onchange .

Android emulator with a testing page for Network Information API

Conclusion

It may not be useful today but as a fangirl for this API I think it was worth it to download Android Studio just for those couple lines of code. Can’t wait until it’s widespread and more advanced.

Network Information API specification

  1. http://www.lonelyplanet.com/estonia/internet-access
  2. I’d love to see autoplay bug/feature dead