Skip to content

Instantly share code, notes, and snippets.

@stefano-bortolotti
Created November 18, 2013 10:28
Show Gist options
  • Save stefano-bortolotti/7525694 to your computer and use it in GitHub Desktop.
Save stefano-bortolotti/7525694 to your computer and use it in GitHub Desktop.
[JS] Determine connection type
/**
navigator.connection is supported on: android 2.2+, Chrome 30+
*/
var connection = navigator.connection || {'type':'0'}, // create a custom object if navigator.connection isn't available
connectionSpeed;
// determine connection speed
switch(connection.type) {
case connection.CELL_3G: // 3G
connectionSpeed = 'fast';
break;
case connection.CELL_2G: // 2G
connectionSpeed = 'slow';
break;
default: // WIFI, ETHERNET, UNKNOWN
connectionSpeed = 'fast';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment