title: Angular 2 - Service worker not found - A bad HTTP response code (404)
body: <p>I used <code>sw-precache</code> to generate a service worker for a <code>Firebase</code> hosted Angular 2 app.</p>
  
  <p>Error: </p>
  
  <pre><code>Service Worker registration failed:  TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
  </code></pre>
  
  <p>Structure</p>
  
  <pre><code>src-
    app--
       index.html    
  service-worker.js
  sw-precache-config.js
  </code></pre>
  
  <p>sw-precache-config.js</p>
  
  <pre><code>module.exports = {
    navigateFallback: '../index.html',
    stripPrefix: 'dist',
    root: 'dist/',
    staticFileGlobs: [
      'dist/index.html',
      'dist/**.js',
      'dist/**.css'
    ]
  };
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;script&gt;
      if ('serviceWorker' in navigator) {
        console.log(navigator.serviceWorker);
  
        navigator.serviceWorker.register('service-worker.js').then(function (registration) {
          console.log('Service Worker registered');
        }).catch(function (err) {
          console.log('Service Worker registration failed: ', err);
        });
      }
    &lt;/script&gt;
  </code></pre>