Last active
October 29, 2015 04:17
-
-
Save deepsweet/4ad4ea7a4b24f22bf7c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isConnectionWorseThan3G() { | |
// https://w3c.github.io/netinfo/#dfn-table-of-maximum-downlink-speeds | |
var mbitsThreshold = 2; | |
var connection = navigator.connection || | |
navigator.mozConnection || | |
navigator.webkitConnection; | |
if (!connection) { | |
return false; | |
} | |
// https://w3c.github.io/netinfo/ | |
if ('downlinkMax' in connection) { | |
return connection.downlinkMax < mbitsThreshold; | |
} | |
// http://www.w3.org/TR/2012/WD-netinfo-api-20121129/ | |
if ('bandwidth' in connection) { | |
return connection.bandwidth * 8 < mbitsThreshold; | |
} | |
// http://davidbcalhoun.com/2010/using-navigator-connection-android/ | |
if ('type' in connection) { | |
return connection.type === connection.CELL_2G; | |
} | |
// default | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment