let type = navigator.connection.effectiveType; function updateConnectionStatus() { console.log( `接続の種類が ${type} から ${navigator.connection.effectiveType} に変化`, ); type = navigator.connection.effectiveType; } navigator.connection.addEventListener("change", updateConnectionStatus); 接続オブジェクトは、大きな帯域幅やメモリが使われるリソースを事前読み込みするかどうか決める場合に便利です。以下の例は、ページの読み込み直後に呼び出され、動画の事前読み込みが望ましくない場合の接続の種類を確かめます。携帯電話回線接続が見つかる