How to Check the Internet Connection Status with JavaScript | Async Await | Offline | Online

  Рет қаралды 11,923

Dave Gray

Dave Gray

Күн бұрын

Пікірлер: 31
@rajashekarkothapelli9649
@rajashekarkothapelli9649 3 жыл бұрын
Hi, its a great video, will it shows network status when the wifi disconnected instead of unchecking offline check box in developer tools, Thanks
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
Thanks! It should detect if it can download the 1 pixel image or not. If not, it will say offline. 👍
@cameronthompson1275
@cameronthompson1275 4 жыл бұрын
Excellent video! Very clear, and easy to understand. Thanks!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
Glad it was helpful! Thank you.
@vladislavkarpov6372
@vladislavkarpov6372 4 жыл бұрын
Thank you for the explanation. I didn't get the trick with the 1pixel.png. Could you please explain this?
@vladislavkarpov6372
@vladislavkarpov6372 4 жыл бұрын
Also, it worked with the browser online tick, but when I turned off wi-fi on my laptop it shows still Online.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
Hello Vladislav and thanks for asking. My explanation in the freeCodeCamp article is the best explanation I have: www.freecodecamp.org/news/how-to-check-internet-connection-status-with-javascript/
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
@@vladislavkarpov6372 for your laptop online issue, I cannot diagnose from here. That said, if you read the provided freeCodeCamp article to understand the 1pixel image usage, this code should provide the results described :)
@CynthiaSotoCaballerolYEAHl
@CynthiaSotoCaballerolYEAHl 4 жыл бұрын
@@DaveGrayTeachesCode Do I need to have the 1pixel.png image in my directory in order to work with this code? Because I'm getting a Not Found error 404
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
@@CynthiaSotoCaballerolYEAHl You do need to have the 1pixel.png in the directory. The 404 indicates you do not have it there. This is just like needing your index.html file there or it will not be found.
@tictactoc9311
@tictactoc9311 2 жыл бұрын
Why are my fetch request remains return true even though I've already turned off my Wi fi?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Are you getting a cached response? Check the network tab in dev tools. You might consider adding cache-busting to your fetch request: developer.mozilla.org/en-US/docs/Web/API/Request/cache
@tictactoc9311
@tictactoc9311 2 жыл бұрын
Wow thanks👍 I didn't expect to get response lol
@shai_guy_chi_guy
@shai_guy_chi_guy 2 жыл бұрын
This is great, extremely useful, and easy to understand. Great work! My only question/concern is that the fetch requests are blowing up my server logs. I assume there isn't a way to turn off logging just for this specific request...
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Probably depends on your server and logging system. I know I could if I used logging middleware in Node.js. Glad the video helped!
@ahmad-murery
@ahmad-murery 4 жыл бұрын
I always check the network/router connection first and if succeeded I go and make a request to the server, this way I can return more accurate information about where the connection has failed (if any) Thanks
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
I'm interested in seeing your code process for this, and is it something you do for all apps you deploy or only on your network?
@ahmad-murery
@ahmad-murery 4 жыл бұрын
@@DaveGrayTeachesCode Thanks Dave, I remember I deployed one web app way back in the past, it uses XHR instead of fetch API, unfortunately it's not online anymore, maybe off-topic but I have implemented the same concept in a desktop DotNet app where the connection is not stable and we needed a way to inform the user about the server availability and whether the disconnection was due to a LAN issue or due to an internet issue (working-offline was not an option), it has a very close implementation to JS where we have a Network.IsAvailable property and a Network.NetworkAvailabilityChanged event listener which I used to update a global app status with corresponding value, in the same time another function is called periodically, it checks the global connection status and then request the server only if the network is available. I believe understanding the concepts is what makes you a better programmer and the code is just your tool to translate that to a working model regardless of the language. Sorry for the long reply.
@thanhkhanhnguyen3850
@thanhkhanhnguyen3850 2 жыл бұрын
what about "How to Check the Website status Up or Down with JavaScript" ?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You would need to be checking a different site. If your site was down, your Javascript would be down, too.
@thearmor9231
@thearmor9231 3 жыл бұрын
Thanks a lots!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
Glad I could help!
@maximumaim
@maximumaim 3 жыл бұрын
Nice coding, thanks sir 😊
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
You're welcome!
@dharmeshgohil9375
@dharmeshgohil9375 2 жыл бұрын
THANK YOU
@maheshm4292
@maheshm4292 4 жыл бұрын
Wow
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
I think that's a good wow 🙂 and if so, you're welcome.
@maheshm4292
@maheshm4292 4 жыл бұрын
@@DaveGrayTeachesCode yes it's a good wow 😂
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
@@maheshm4292 😂 Right on!
@namsraikhatanbaatar9932
@namsraikhatanbaatar9932 4 жыл бұрын
Sass :D
Callbacks, Promises, Async Await | JavaScript Fetch API Explained
1:05:05
Check Internet Connection Status With Javascript
7:35
Coding Artist
Рет қаралды 3,5 М.
Как Ходили родители в ШКОЛУ!
0:49
Family Box
Рет қаралды 2,3 МЛН
The ONLY REASON To Unit Test
8:26
Theo - t3․gg
Рет қаралды 89 М.
How to get your Internet Connection Information using JavaScript
24:21
Oston Code Cypher
Рет қаралды 3,3 М.
Always Check for the Hidden API when Web Scraping
11:50
John Watson Rooney
Рет қаралды 661 М.
JavaScript Online Offline Events
5:58
Code With Bubb
Рет қаралды 1,4 М.
JavaScript Async Await
7:31
Web Dev Simplified
Рет қаралды 829 М.
React js pwa tutorial #8 check Internet connection and load page offline
5:25