title: Angular 5 Service worker not working / Doesn't cache background-image
body: <p>I'm having trouble getting my angular5 service worker to work. I have two main problems:</p>
  
  <ol>
  <li>The service worker doesn't cache assets images that are used as background-images</li>
  <li>After simulating a network disconnect the service worker initially pulls files from the cache (except the the aforementioned non cached files), but after a second refresh it runs into an error.</li>
  </ol>
  
  <p>Below is a more detailed report of my problem. You can follow along by cloning a repo I made to highlight this problem located <a href="https://github.com/osa10928/test-angular5-serviceWorker" rel="noreferrer">here.</a></p>
  
  <p>I created the application with the --service-worker tag provided. I then ensured that the 5 steps listed on the Angular documentation <a href="https://angular.io/guide/service-worker-getting-started" rel="noreferrer">here</a> were followed, namely:</p>
  
  <ol>
  <li>Service worker package is added.</li>
  <li>angular-cli.json has service-worker set to true</li>
  <li>Service worker is imported and registered in app.module.ts</li>
  <li>ngsw-config.json was generated and configured as described in the documentation.</li>
  <li>Run ng build --prod to generate bundles in my dist folder of the application.</li>
  </ol>
  
  <p>I serve my application using node/express and a server.js document. When I open the application in an incognito window (as recommended by the documentation) I see my service worker gets registered and a cache stores my bundles and index file. It also caches the image that is used in an img tag, but it does not cache the images specified in my css background-image. When I simulate a network problem by checking the offline box on my service worker and then refresh my page, the page displays everything correctly except the parts that require background images.</p>
  
  <p>But the final/main problem occurs when I refresh the application a second time or open another tab (on the same incognito window so the service worker is still registered and cache is still active). At this point I get nothing displayed. The console gives me three error:</p>
  
  <ol>
  <li>GET <a href="http://localhost:3000/favicon.ico" rel="noreferrer">http://localhost:3000/favicon.ico</a> net::ERR_INTERNET_DISCONNECTED</li>
  <li>An unknown error occurred when fetching the script.</li>
  <li>Failed to load resource: net::ERR_INTERNET_DISCONNECTED</li>
  </ol>
  
  <p>with the last error coming from ngsw-worker.js. I'm not quite sure what to make of these error. I think maybe a new service worker is trying to be registered but I'm not sure why that would happen...</p>
  
  <p>here is my ng-config.json file as requested:</p>
  
  <pre><code>{
    "index": "/index.html",
    "assetGroups": [{
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "/favicon.ico",
          "/index.html"
        ],
        "versionedFiles": [
          "/*.bundle.css",
          "/*.bundle.js",
          "/*.chunk.js"
        ]
      }
    }, {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**"
        ]
      }
    }]
  }
  </code></pre>
  
  <p>Any help with this would be greatly appreciated! Thanks all</p>
  
  <p><strong>Update</strong></p>
  
  <p>So I've noticed that when I go to localhost:3000 without the server running I get the error:</p>
  
  <pre><code>Uncaught (in promise) Error: Response not Ok (fetchAndCacheOnce): request for http://localhost:3000/assets/images/background-silver-grainy.jpg returned response 504 Gateway Timeout
  </code></pre>
  
  <p>I also get the errors:</p>
  
  <pre><code>Failed to load resource: the server responded with a status of 504 (Gateway Timeout)
  </code></pre>
  
  <p>Comming from all my resources</p>
  
  <p><strong>Update2</strong></p>
  
  <p>I've been testing this project using node to serve an express application that directs all requests to my angular application located in a dist folder (which is generated after running ng build --prod). I decided to test it on a simple http-server. I also found that doing a direct reload breaks my service worker, but if I navigate to another page, then back to my original page, the service worker works (weird but unrelated to this question).</p>
  
  <p>I still can't get the service worker to work with express though...</p>