What value would the effectiveType property return for a user on a technically 4G connection that's performing poorly?
function getNetworkInfo() {
if ('connection' in navigator) {
const conn = navigator.connection ||
navigator.mozConnection ||
navigator.webkitConnection;
return {
type: conn.type,
effectiveType: conn.effectiveType,
downlinkMax: conn.downlinkMax,
downlink: conn.downlink,
rtt: conn.rtt,
saveData: conn.saveData
};
}
return null;
}
function adaptToNetwork() {
const netInfo = getNetworkInfo();
if (netInfo) {
if (netInfo.saveData || netInfo.effectiveType === 'slow-2g' || netInfo.effectiveType === '2g') {
loadLowResImages();
} else {
loadHighResImages();
}
} else {
// Network info not available, load default
loadDefaultImages();
}
}
The effectiveType property reports connection quality, not just technical type: 1) It categorizes connection performance into four categories: 'slow-2g', '2g', '3g', and '4g', 2) These categories are based on actual measured network performance, not just the technical connection type, 3) A nominal 4G connection with poor performance might report as '3g' or even '2g', 4) This makes it more useful than the type property, which reports technical connection types like 'wifi' or 'cellular', 5) The categorization uses metrics like round-trip time (RTT) and downlink speed, 6) This enables web applications to adapt content delivery based on real-world performance rather than theoretical connection capabilities, 7) The code properly uses this property to make adaptive decisions about resource loading, 8) This approach is part of the broader concept of adaptive loading, tailoring experiences to network conditions.