let type = navigator.connection.effectiveType;
function updateConnectionStatus() {
console.log(
`Connection type changed from ${type} to ${navigator.connection.effectiveType}`,
);
type = navigator.connection.effectiveType;
}
navigator.connection.addEventListener("change", updateConnectionStatus);Network Information API / notebook
Network Information API
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
let preloadVideo = true;
const connection = navigator.connection;
if (connection) {
if (connection.effectiveType === "slow-2g") {
preloadVideo = false;
}
}