Is there a way to determine the speed of 3G and 2G connections on mobile phones and handheld devices?

Is there a way to detect 3G and 2G connections on mobile phones and handheld devices?

For example, if I want to deliver a High-End Website when the user is connected to 3G and highly optimized if the user is on 2G.

+3
source share
2 answers

In Android 2.2+, there is a JS object for this.

You can write a class to use CSS depending on the type of connection. But it is not available on iOS for mobile websites, as far as I know.

var connection, connectionSpeed, htmlNode, htmlClass;
connection = navigator.connection || {"type":"0"}; // fallback

switch(connection.type) {
  case connection.CELL_3G: connectionSpeed = "mediumbandwidth"; break;
  case connection.CELL_2G: connectionSpeed = "lowbandwidth"; break;
  default: connectionSpeed = 'highbandwidth';
}

/* set the connection speed on the html element
   i.e. <html class="lowbandwidth">
*/
htmlNode = document.body.parentNode;
htmlClass = htmlNode.getAttribute("class") || "";
htmlNode.setAttribute("class", htmlClass + " " + connectionSpeed);

Code from slide 24 in this presentation:
http://davidbcalhoun.com/present/mobile-performance/

+3

http.

, cookie

0

All Articles