title: update index.html in angularjs
body: <p>Currently our website in angularjs is not updated by latest javascript version without doing hard refresh is browser. In order to update it on real time basis, we have started sending a custom header (APP-VERSION) in our rest API based on which we can reload the page which results in updating the website by latest javascript version.
  This version comparision code is written in javascript is the HTTP interceptor which is not updated on client side. 
  In order to update index.html, we have tried various scenario which are as follows:-
  1.We have changed the name of index.html to default.html but still it is not updated on client side.
  2.We have changed the path (/test/index.html) of index.html, still its not working.
  3.We have used on-page script on every page, we got a warning "Trying to load angularjs twice".
  4.We have added the custom header (add_header Cache-Control no-cache;) in the config file on nginx which is also not working/</p>
  
  <p>Please help us how to forcefully update the index.html on client side.</p>
  
  <p>Please find the code index.html, HTTPInterceptor, and route.js</p>
  
  <p>index.html:-</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon"&gt;
  &lt;link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet"&gt;
  &lt;link rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/WebRupee/2.0/font.min.css" /&gt;
      &lt;link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet"&gt;
  &lt;!--&lt;link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.504/styles/kendo.common.min.css"/&gt;
      &lt;link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.504/styles/kendo.rtl.min.css"/&gt;
      &lt;link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.504/styles/kendo.silver.min.css"/&gt;
      &lt;link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.504/styles/kendo.mobile.all.min.css"/&gt;
   --&gt;
  &lt;link rel="stylesheet" href="/css/mrConsultant.min.css?ver=@@cssVer"&gt;
  &lt;!-- &lt;link rel="stylesheet" href="css/preLoginPartner.css"&gt; --&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;base href="/"&gt;
  &lt;!-- Google Tag Manager --&gt;
  &lt;script&gt;
  @@gtmScript
  &lt;/script&gt;
  &lt;!-- End Google Tag Manager --&gt;
  
  &lt;/head&gt;
  &lt;body ng-app="myApp" ng-cloak layout="column"&gt;
  
      &lt;div flex layout="column"&gt;
          &lt;div ng-view flex layout="column"&gt;&lt;/div&gt;
      &lt;/div&gt;
  
  &lt;!-- Google Tag Manager (noscript) --&gt;
  &lt;noscript&gt;
  @@gtmNoScript
  &lt;/noscript&gt;
  &lt;!-- End Google Tag Manager (noscript) --&gt;
  
  &lt;/body&gt;
  
  
  &lt;script type="text/javascript" src="js/mrConsultant.min.js?ver=@@jsVer"&gt;&lt;/script&gt;
  &lt;!--&lt;script src="http://kendo.cdn.telerik.com/2016.2.504/js/kendo.all.min.js" &gt;&lt;/script&gt;
  &lt;script src="http://kendo.cdn.telerik.com/2016.2.607/js/kendo.timezones.min.js" &gt;&lt;/script&gt;--&gt;
  &lt;!--&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/ngStorage/0.3.6/ngStorage.min.js" async&gt;&lt;/script&gt;--&gt;
  &lt;script src="http://ngmaterial.assets.s3.amazonaws.com/svg-assets-cache.js"&gt;&lt;/script&gt;
  &lt;!--&lt;script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-beta.2/angular-sanitize.js"&gt;&lt;/script&gt;--&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/angular-sanitize/1.6.1/angular-sanitize.min.js"&gt;&lt;/script&gt;
  &lt;noscript&gt;test scritp&lt;/noscript&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>HTTPInterceptor:-</p>
  
  <pre><code>myApp.factory('HTTPInterceptor', ['$location','$q','API_URL','version','CookieService','$templateCache','$window',function ($location,$q,API_URL,version,CookieService,$templateCache,$window) {
      return {
          'request': function (config) {
              if ((config.url.indexOf('.html') ==-1) &amp;&amp; (config.url.indexOf('.svg')==-1)) {
                  config.url = API_URL + config.url;
                  if ((config.url.indexOf('/forgot-password-consultant')==-1) &amp;&amp; (config.url.indexOf('/reset-password-consultant')==-1)) {
  
                      config.headers['Authorization'] = CookieService.getCookie('AUTH_TOKEN');
                  }
  
                  config.headers['Accept'] = "application/vnd.refer.v1+json";
              }
              return config;
          },
          'response': function (resp) {
              function createCustomAlert() {
                  d = document;
                  if(d.getElementById("website-update")) return;
  
                  mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
                  mObj.id = "website-update";
                  style = mObj.appendChild(d.createElement("style"));
                  style.innerHTML = "@import url('https://fonts.googleapis.com/css?family=Roboto')";
  
                  alertObj = mObj.appendChild(d.createElement("div"));
                  alertObj.id = "website-update-card";
  
                  h1 = alertObj.appendChild(d.createElement("h1"));
                  h1.appendChild(d.createTextNode("UPDATE ALERT"));
  
                  msg = alertObj.appendChild(d.createElement("p"));
                  msg.innerHTML = "A new version of Refer is available now. Update now for better performance.";
                  msg1 = alertObj.appendChild(d.createElement("p"));
                  msg1.innerHTML = "If you are on an important task, continue your work and you can update on next page.";
  
                  updateBtn = alertObj.appendChild(d.createElement("button"))
                  updateBtn.id = "website-update-btn";
                  updateBtn.innerHTML = "Update Now";
                  updateBtn.onclick = function() { clearTemplateCache();return true; }
  
                  notUpdateBtn = alertObj.appendChild(d.createElement("button"))
                  notUpdateBtn.id = "website-update-notnow";
                  notUpdateBtn.innerHTML = "Not now";
                  notUpdateBtn.onclick = function() { removeCustomAlert();return false; }
              }
  
              function removeCustomAlert() {
                  document.getElementsByTagName("body")[0].removeChild(document.getElementById("website-update"));
              }
  
              function clearTemplateCache() {
                  document.getElementsByTagName("body")[0].removeChild(document.getElementById("website-update"));
                  $templateCache.removeAll();
                  $window.location.reload();
              }
  
              if (resp.status === 401) {
                  $templateCache.removeAll();
                  $window.location.reload();
                  $location.path('/logout');
              }/*else if(resp.status === 200 &amp;&amp; resp.headers('app-version') != null &amp;&amp; resp.headers('app1-version') != version){
                  createCustomAlert();
              }*/
              return resp;
          },
          'responseError': function (rejection) {
              if(rejection.status === 401) {
                  $templateCache.removeAll();
                  $location.path('/logout');
              }
              return $q.reject(rejection);
          }
      };
  }]);
  
  myApp.config(['$httpProvider', function ($httpProvider) {
      $httpProvider.interceptors.push('HTTPInterceptor');
  }]);
  </code></pre>
  
  <p>route.js:-</p>
  
  <pre><code>myApp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
  
      if(window.history &amp;&amp; window.history.pushState){
          $locationProvider.html5Mode({
              enabled: true,
              requireBase: true,
              rewriteLinks: true
          });
      }
  
      $routeProvider.when('/unicorn-:startups-:consultant-:register', {
          templateUrl: 'views/registerCampaign.html',
          controller: 'RegisterController',
          controllerAs: 'registerCtrl'
  
      }).when('/register', {
          templateUrl: 'views/register.html',
          controller: 'RegisterController',
          controllerAs: 'registerCtrl'
  
      }).when('/login', {
          templateUrl: 'views/login3.html',
          controller: 'LoginController',
          controllerAs: 'loginCtrl',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      $location.path('/jobs')
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/forgot-password', {
          templateUrl: 'views/forgotPassword.html',
          controller: '' +
          'forgotPasswordController'
  
      }).when('/reset-password/:token/:sm', {
          templateUrl: 'views/resetPassword.html',
          controller: 'resetPasswordController'
  
      }).when('/logout', {
          resolve: {
              auth: ['$location', 'UserService', function ($location, UserService) {
                  UserService.logout();
                  $location.path('/login');
                  $location.replace();
              }]
          }
      }).when('/', {
          templateUrl: 'views/dashboard.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      $location.path('/dashboard')
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/dashboard', {
          templateUrl: 'views/dashboard1.html',
  
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      $location.path('/dashboard')
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/jobs/:jobType', {
          templateUrl: 'views/jobs.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/jobs.html'
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/job-detail/:jobId', {
          templateUrl: 'views/job-detail.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/job-detail.html'
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/direct-apply/:jobId', {
          templateUrl: 'views/apply-new.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/apply-new.html'
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/performance', {
          templateUrl: 'views/performance.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      $location.path('/performance')
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/calendar', {
          templateUrl: 'views/calender.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      $location.path('/calendar')
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/tracker', {
          templateUrl: 'views/tracker.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      $location.path('/tracker')
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/internal-jobs', {
          templateUrl: 'views/internal-jobs.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      $location.path('/internal-jobs')
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/assigned-jobs', {
          templateUrl: 'views/assigned-jobs.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      $location.path('/assigned-jobs')
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/suggested-candidates/:jobId', {
          templateUrl: 'views/suggested-candidates.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/suggested-candidates.html'
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/suggested-apply/:jobId', {
          templateUrl: 'views/apply-suggested.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/apply-suggested.html'
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
  
  
      }).when('/edit-candidate/:jobId', {
          templateUrl: 'views/edit-candidate.html',
  
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/edit-candidate.html'
                  } else {
                      $location.path('/login');
                  }
              }]
          }
  
      }).when('/database', {
          templateUrl: 'views/database.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/database.html'
                  } else {
                      $location.path('/login');
                  }
              }]
  
          }
  
      }).when('/database-search', {
          templateUrl: 'views/database-search.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/database-search.html'
                  } else {
                      $location.path('/login');
                  }
              }]
  
          }
  
      }).when('/database-search-result', {
          templateUrl: 'views/database-search-result.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/database-search-result.html'
                  } else {
                      $location.path('/login');
                  }
              }]
  
          }
  
      }).when('/review-compare', {
          templateUrl: 'views/review-compare.html',
          resolve: {
              userInfo: ['$location', 'UserService', function ($location, UserService) {
                  if (UserService.session()) {
                      templateUrl: 'views/review-compare.html'
                  } else {
                      $location.path('/login');
                  }
              }]
  
          }
  
      }).when('/add-new', {
              templateUrl: 'views/add-contact.html',
              resolve: {
                  userInfo: ['$location', 'UserService', function ($location, UserService) {
                      if (UserService.session()) {
                          templateUrl: 'views/add-contact.html'
                      } else {
                          $location.path('/login');
                      }
                  }]
              }
  
          })
          .otherwise({
              redirectTo: '/'
          });
  
  }]);
  
  myApp.run(['$rootScope', '$templateCache', function ($rootScope, $templateCache) {
      $rootScope.$on('$viewContentLoaded', function () {
          $templateCache.removeAll();
      });
  }]);
  </code></pre>
  
  <p>nginx settings:-</p>
  
  <pre><code>    location / {
      add_header Cache-Control no-cache;
      root   D:\refer-workspace\consultant_web;       
      try_files $uri $uri/ /index.html/ =404;
      expires -1;
  
      }
  </code></pre>
  
  <p>Thanks in advance.</p>