TIL about the Network Information API
POSTED ON:
NOTE: This only works in Chrome/Chromium (like Edge)
Safari and Firefox have experimental versions that they're working on. But some requires the flag to be turned on.
The Network Information API provides information about the network types(e.g., 'wifi', 'cellular', etc.), save data mode, bandwidth and many more.
let preloadVideo = true;
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
if (connection) {
if (connection.effectiveType === 'slow-2g') {
preloadVideo = false;
}
}
Direct link to the demo: https://demo.greenroots.info/web-apis/web-api-network-info/
via Tapas Adhikary's 10 lesser-known Web APIs you may want to use
Related TILs
Tagged: browser