Angular 6 service worker and routing

Viewed 589

I have an Angular 6 app which is working fine but only until I have published an update.

The service worker is requesting an old version of the runtime[hash].js script. Is this normal? My understanding is that the service worker should request the scripts as defined in the ngsw.config and use the hash table therein to determine if a request for a resource from the server is necessary.

Also, my (simplified) app routing is as follows:

{
    path: 'login',
    component: LoginComponent
}, 
{
    path: 'logout',
    component: LogoutComponent
}, 
{
    path: 'error',
    component: ErrorComponent
}, 
{
    path: '**',
    pathMatch: 'full',
    component: PageNotFoundComponent
}

This seems to compound the problem as the catch-all route that directs to the 'PageNotFoundComponent' seems to come into play. For example, if I request a script that doesn't exist, I get the PageNotFoundComponent.

This causes an unexpected token '<' error in the browser (I presume from where a script tag is actually expecting some script and not the html of the 404 page).

Why does the angular routing seem to be playing a part here? If I request a script that exists, I get the script content returned (so seemingly not affected by the routing) but only when it doesn't do I get the 404 page.

edit Just to add, I'm attaching the response from the request to ngsw.json. This shows the hash table of the scripts / resources. In there I only see the one, latest copy of the runtime.js.

enter image description here

0 Answers
Related