Utility that tries to figure out if you are on cellular or broadband. It either uses the Network Information API (browser support) or falls back to measuring latencies via Resource Timing API (browser support). If none of them is available, it will get the client's public IP from ipify and compare that with the GURFL list of mobile carrier IP blocks. If the connection type can not be specified, it will settle on broadband by default.
Include connection-type-checker.js script in your HTML file:
<script src="connection-type-checker.js"></script>Execute connectionTypeChecker.getConnectionType method with a callback function:
connectionTypeChecker.getConnectionType(function(result) {
alert(result);
});'offline'for whennavigator.onLinereturnsfalseor the Network Information API returns'none', or when Resource Timing AJAX call fails.'cellular'for when the Network Information API returns'cellular'or'bluetooth', or when Resource Timing API measures latencies >= 100 ms, or when the client's IP is amongst the list of mobile carriers.'broadband'for when the Network Information API returns'wifi','wimax'or'ethernet', or when Resource Timing API measures latencies < 100 ms, when the client's IP is not amongst the list of mobile carriers, or as the fallback value when none of the aforementioned works out.