0

I have this web application (MVC using C#) that serves like an advertisement in my client's office. My client will open this "advertisement page" and display it on a big screen to their customers.

What happen is, every 30 minutes or so, the page will automatically refresh to fetch latest data from the database, however, they are using WIFI to connect to our server and sometimes the connection is very slow (or lost connection completely). My client requested me to write a code to prevent the page from refreshing if the connectivity is bad or no internet connection. (They do not want to show "No Internet Connection" on their advertisement TV)

I know I cannot do anything from the server side code because it is the client's machine that want to detect the internet connection, so leaving client side code as the only option. I am not good at this, can anyone help me out?

C.J.
  • 3,409
  • 8
  • 34
  • 51

3 Answers3

4

I'd suggest a "ping" sent via ajax:

var timeStart= new Date().getTime();
$.ajax({
    url:"url-to-ping-response-file",
    success:function(){
        var timeNow = new Date().getTime();
        var ping = timeNow - timeStart;

        //less than one second
        if(ping < 1000){
            window.location.reload();
        }
    }
});
Mr.Manhattan
  • 5,315
  • 3
  • 22
  • 34
1

You can use the Circuit Breaker Pattern to gracefully handle intermittently connected environments.

Here are 2 open source JavaScript implementations. I have never used either of them, so I cannot attest to their quality.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
0

You can also make use of

 if (navigator.onLine) {
        location.reload();
    }

This will not detect slow internet. Now, I don't understand your web layout but for sites that I work on I tend to get HTML content and DATA as separate calls. I do this with a MVVM/MVC pattern which is worth learning. I use angularjs it is very awesome.

Now.. you can also use good old jQuery to replace the content have a read of this Replace HTML page with contents retrieved via AJAX you could couple this with the .onLine check.

http://www.w3schools.com/jsref/prop_nav_online.asp

Community
  • 1
  • 1
Steve Drake
  • 1,968
  • 2
  • 19
  • 41