Go back to the main page

Detect internet connection before refreshing the page


It is important to automatically and wisely (not in the middle of them typing something,etc.) refresh a web application to make sure the content is fresh. Don't make your users do this manually. However, adding this feature can back fire in a ugly "Page not found" if you don't first check to see that the user has a internet connection. This step, where you check first, may not get done as the application developers generally will have reliable connections and may not notice. Many of your users may be on satellite, 3G, or some home-brew wireless system where reliability is inconsistent. Here is what I do for the Simplton town's folk.

    // Front end: Prototype based code
    // Ajax call here to determine that the network is up
    new Ajax.Request('/signal/ping', {
        if(response.status == 200){
    # Back end: Example in Rails; Controller is "signal"
    def ping
      # Only a sent status of 200 OK will refresh the page
      render :inline => ''
  • Pushed on 10/22/2010 by Christian