Skip to content

Instantly share code, notes, and snippets.

@deepsweet
Last active October 29, 2015 04:17
Show Gist options
  • Save deepsweet/4ad4ea7a4b24f22bf7c7 to your computer and use it in GitHub Desktop.
Save deepsweet/4ad4ea7a4b24f22bf7c7 to your computer and use it in GitHub Desktop.
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