title: Angular - Service worker not applying the updates immediately
body: <p>We are using Angular 8 with .NET Web API. Recently we made a major change on UI side, which impacted end users, because service worker is not applying the latest changes from server immediately. Latest updates are applied on end user browser only after refreshing the browser or reopening the browser in next tag.</p>
  <p>But we want to refresh the browser immediately once the update is available. Under developer tools we can see Service worker is pulling the latest changes, but not applying immediately.</p>
  <p>Below picture from my browser - Service Worker showing the update available in browser</p>
  <p>We tried to create our own ngsw-serviceworker.js file, but after post deployment script we can't see our own file. Angular creating default ngsw-serviceworker.js from service worker package.</p>
  <p>This is the piece of code we wrote for force refresh if any update is available. But no luck, even this code is applying only if browser if reopened.</p>
  <p>version we used -
  &quot;@angular/service-worker&quot;: &quot;8.2.14&quot;,
  Angular 8.</p>
  <h2>Angular.json</h2>
  <p>&quot;serviceWorker&quot;: true,
  &quot;ngswConfigPath&quot;: &quot;ngsw-config.json&quot;</p>
  <h2>App.Component.ts: (below is the code we wrote in constructor)</h2>
  <pre><code>  if (this.swUpdate) {
     this.swUpdate.available.subscribe((event) =&gt; {
      console.log(`current`, event.current, `available `, event.available);
      this.swUpdate.activateUpdate().then(() =&gt;
      {
        location.reload();
      
      }
      ); 
    });
  </code></pre>
  <p>Can someone please help us to find the solution, to apply html/js/CSS changes on user browser from server or reload the browser immediately once the service worker update is available.</p>
  <p>Our UI code is deployed on cloud, AWS.</p>