Network Information API
Published on 2017-03-17 12:00If 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. Estonia[1. http://www.lonelyplanet.com/estonia/internet-access] is an exception, not a rule.
Another place where I would love to see this are video players which could give option to the user before attempting to play the content[2. I'd love to see autoplay bug/feature dead]. 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:
You can assign your own connection change function to the the event listener navigator.connection.onchange .
ConclusionIt 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