Skip to content
JsDevLife
Menu
  • Home
  • Leetcode in JS
  • About me
  • Contact Us
Menu

Javascript detect connection speed

Posted on August 29, 2019 by Vikas Kad

JavaScript detect connection speed


Ever feel like your internet is running slow? Webpages seem sluggish while uploads and downloads take forever! It’s very frustrating, especially when you pay for high-speed internet.

As a developer, we need to find the current speed and load the pages accordingly. So if you want to get the connection speed in JS you can use the Navigator.connection object.

Let’s take an example:

navigator.connection.addEventListener(‘change’, () => {
let currRtt = navigator.connection.rtt;
let effType = navigator.connection.effectiveType;
console.log(‘current connections’, currRtt, effType)
})

so the above example will trigger an event whenever there will be some changes in the network.

So let’s test it by changing the network connections.
Javascript detect connection speed

As you can see in logs whenever I changed the network type from network tab events gets fired and it printed the current connections types.

Javascript detect connection speed example


I hope you will get more idea about the connection object from Javascript.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Solving LeetCode Problem 79 – Word Search in JavaScript
  • Solving LeetCode Problem 48: Rotate Image using JavaScript
  • Solving the “Container With Most Water” LeetCode Problem in JavaScript – A Comprehensive Guide
  • LeetCode Solution: 54: Spiral Matrix in JavaScript
  • Solution to LeetCode Problem 31. Next Permutation in JavaScript

Archives

  • 2023 (5)
  • 2022 (20)
  • 2021 (2)
  • 2020 (4)
  • 2019 (14)
  • 2018 (17)

Categories

  • blockchain development
  • Blog
  • crystal
  • flutter
  • flutter.io
  • GitHub
  • Installation
  • Ionic Framework
  • javascript
  • leetcode-in-js
  • masteringInJavasript
  • mcqs
  • MongoDB
  • nodejs
  • Object Oriented Javacript
  • python
  • smart contracts
  • visual studio

Quick Links

  • Home
  • Leetcode in JS
  • About me
  • Contact Us

Terms of service

  • Terms Of Service
  • Disclaimer
©2023 JsDevLife | Design: Newspaperly WordPress Theme