Skip to content

[ServiceWorker] localhost took too long to respond. HTTP ERROR 504 #21636

Closed
@NgxDev

Description

@NgxDev

I'm submitting a...

[x] Bug report

Minimal reproduction of the problem with instructions

  1. ng new sw --service-worker --routing
  2. cd sw
  3. ng g c home
  4. ng g c about
  5. Edit app-routing.module.ts to add the routes for the 2 components we've just created:
// ...
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';

const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'about', component: AboutComponent }
];

// ...
  1. ng build --prod
  2. npm install -g http-server (you can use any server to test this, if you already prefer another one)
  3. http-server dist
  4. Access localhost:8080 (8080 is the default port that http-server uses at the time of reporting this issue)
  5. Access localhost:8080/about
  6. Stop the server
  7. Now try reloading the app while on the /about route (if it works the first time, try refreshing a few more times or wait a little before trying again). The browser will display the message:
This page isn’t working
localhost took too long to respond.
HTTP ERROR 504

(With Universal/SSR, it stops working right away, most of the time with the first refresh after stopping the server, no matter the route - and the issue is not the hash in the generated ngsw.json, because I regenerate that at the end of the build process).

Now, if you start the server again, loading the app on the /about route works (even though http-server is not SPA friendly, it doesn't redirect all requests to index.html), but the service worker kicks in.
Initially I noticed this behavior on a Universal app, doing server side rendering (following the universal-starter repo). So this is not a http-server "not being SPA friendly" issue.
I only used http-server to reproduce it because I wanted to keep the reproduction process as fast as possible, without introducing server side rendering.
The CLI version used (1.6.4) initializes the app with Angular 5.1.0, but I've also tested on 5.2.1. I've skipped mentioning this step above because it happens regardless of the Angular version (at least on >= 5.1.0, haven't tested with older versions).

Environment

Angular CLI: 1.6.4
Node: 8.9.4
OS: win32 x64
Angular: 5.2.1

Browser:
I've only tested on:
- [x] Chrome (desktop) version 63.0.3239.132
- [x] Chrome (desktop) version 65.0.3323.2 (canary)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions