2

I have an anguler 6 app which has a service worker and when we deploy and then load our site, the index.html file seems to be cached by the service worker. The CSS file that is referenced in the index.html is an old hashed file, which results in index.html being returned as the CSS file and I get the error in the console "Uncaught SyntaxError: Unexpected token <" If I open chrome dev tools and check the "Bypass for network" checkbox for the service worker, then I don't get this issue. Below is my ngsw-config.json

{
    "index": "/index.html",
    "assetGroups": [{
        "name": "MyApp",
        "installMode": "prefetch",
        "resources": {
            "files": [
                "/favicon.ico",
                "/index.html",
                "/manifest.json",
                "/*.css",
                "/*.js"
            ]
        }
    }, {
        "name": "assets",
        "installMode": "lazy",
        "updateMode": "prefetch",
        "resources": {
            "files": [
                "/assets/**"
            ]
        }
    }]
}
CaptainMorgan
  • 1,193
  • 2
  • 25
  • 55
  • `which results in index.html being returned as the CSS file` I don't understand that statement. Why would the `index.html` yield an old CSS file that has a hashed name? – Reactgular Jan 18 '19 at 02:52
  • is in my index.html, but the hash is a previous version. Since it can't be found and due to routing setup, index.html is returned. Anyway. I need to know how to stop service worker from caching index.html – CaptainMorgan Jan 18 '19 at 03:01
  • Ofcourse, that makes sense. – Reactgular Jan 18 '19 at 03:07
  • I had the same problem. I posted my answer here how I solved it: https://stackoverflow.com/a/68211878/14389830 – NeNaD Jul 01 '21 at 14:20

0 Answers0