Skip to content

Commit

Permalink
lowbandwidth test also satisfies current draft of spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Dec 5, 2011
1 parent 23d57f1 commit c56fb8b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions feature-detects/network-connection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@

// determining low-bandwidth via navigator.connection
// this object only exists in Android 2.2+ and only in the Browser (not WebView)

// docs.phonegap.com/en/1.2.0/phonegap_connection_connection.md.html#connection.type
// davidbcalhoun.com/2010/using-navigator-connection-android
// There are two iterations of the navigator.connection interface:

// The first is present in Android 2.2+ and only in the Browser (not WebView)
// : docs.phonegap.com/en/1.2.0/phonegap_connection_connection.md.html#connection.type
// : davidbcalhoun.com/2010/using-navigator-connection-android

// The second is specced at dev.w3.org/2009/dap/netinfo/ and perhaps landing in WebKit
// : bugs.webkit.org/show_bug.cgi?id=73528

// unknown devices are assumed as fast
// for more rigorous network testing, consider boomerang.js: github.com/bluesmoon/boomerang/
Expand All @@ -12,6 +17,7 @@ Modernizr.addTest('lowbandwidth', function(){

var connection = navigator.connection || {type:0, UNKNOWN: 0}; // polyfill

return connection.type === connection.CELL_2G || connection.type === connection.CELL_3G;

return connection.type === 3 // connection.CELL_2G
|| connection.type === 4 // connection.CELL_3G
|| !!navigator.connection.type.match(/^(?:2g|3g)$/); // string value in new spec

This comment has been minimized.

Copy link
@mathiasbynens

mathiasbynens Dec 6, 2011

Contributor

Shouldn’t this be connection instead of navigator.connection?

Also, if you need a boolean anyway you might as well use .test(): /^(?:2g|3g)$/.test(connection.type). This should be faster, too!

Update: pull request #427

});

0 comments on commit c56fb8b

Please sign in to comment.