title: How to reload the page if the server is offline?
body: <p>When deploying our app we use <code>app_offline.htm</code> to tell IIS to make our application unavailable. If there are any clients that have the Angular app loaded already, what I would like to do is intercept any requests to the server while the app is offline and then reload the page so that <code>app_offline.htm</code> displays instead of the Angular app.</p>
  
  <p>I thought it would be as simple as putting <code>&lt;!--Offline--&gt;</code> or something at the top of <code>app_offline.htm</code> and then have an http interceptor that checks if any response starts with that, but I never seem to get the content of <code>app_offline.htm</code> in a response. Amazingly, I'm still getting app content in the responses. I'm wondering if maybe it's pulling a cached version of the content or something. If I manually reload the page, I do get the <code>app_offline.htm</code> page as expected.</p>
  
  <p>So how can I detect if the server is unavailable and reload the page?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>So this appears to maybe be more of an IIS configuration issue than anything. The <code>app_offline.htm</code> file appears to only affect resources managed by ASP.NET. From <a href="https://stackoverflow.com/a/4916070/64279">this answer</a>, I learned that you can configure ASP.NET MVC to handle all requests using this following code:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
      &lt;system.webServer&gt;
          &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>This has the effect of preventing static content like HTML from being served even if <code>app_offline.htm</code> exists, but it also appears to continue firing the 'response' handler of the Angular http interceptor with <code>undefined</code> as the response instead of firing the 'responseError' handler with an object having a status of 503 Service Unavailable. I'm hesitant to use this solution because I don't know if there are other conditions that may cause an <code>undefined</code> response, but so far it appears to be working:</p>
  
  <pre><code>function appOfflineHttpInterceptor($window, $q) {
      return {
          'response': function (response) {
              if (typeof response == "undefined")
                  $window.location.reload();
  
              return response || $q.when(response);
          }
      };
  }
  </code></pre>
  
  <p>Does anyone know if there are other conditions that would cause an undefined response - which would render this solution nonviable?</p>