3

I you go to the app https://quotesaboutjesus.netlify.com/quotes and look at Application tab in Chrome Dev tool, you'll see after few seconds the service worker runing well... and the app work well in online mode.

But Lighthouse audit result always says me :

  • Current page does not respond with a 200 when offline.
  • start_url does not respond with a 200 when offlineThe start_url did respond, but not via a service worker.
  • Does not register a service worker that controls page and start_url

But as you'll see in my code here or directly in my manifest.webmanifest here, i did (i think ?: because Lighthouse says me i didn't) :

  1. add a web app manifest.
  2. Check that the start_url in your manifest is correct.
  3. Add a service worker to your app.
  4. Use the service worker to cache files locally.
  5. When offline, use the service worker as a network proxy to return the locally cached version of the file.

So i don't understand why i fails the audit test (you can easily reproduce it yourself online).

i imagined that it can be cause by the fact that my SW register a little late, so i try to optimise the performance of the app, but even now it has better performances score (90 at least during audit test), it's didn't pass this test.

Can someone help me ?

Image showing the Lighthouse error messages

Image showing the service worker working well

Image Showing the (start_ul in) manifest

WilChrist
  • 43
  • 4
  • perhaps try changing your start_url to /quotes – Mathias Jan 10 '20 at 15:09
  • Hi @Mathias quotes is where / redirect to, not the base url. But i'll give a try. – WilChrist Jan 10 '20 at 15:14
  • Redirects may be causing your issue (not sure). Usually, people place everything at the base – Mathias Jan 10 '20 at 15:16
  • in fact it's a angular redirection not a server's one. i tried by changing to /quotes as you suggested, but it doesn't resolve the issue. – WilChrist Jan 10 '20 at 15:22
  • Are you sure you uploaded a new manifest? I just checked and it is still this "start_url": "/", – Mathias Jan 10 '20 at 15:25
  • no, i did the test locally, but if you want i can push it. – WilChrist Jan 10 '20 at 15:30
  • I'm not sure it would work differently there, so don't do the extra work. – Mathias Jan 10 '20 at 15:31
  • Usually, the Lighthouse hints are very close to what you need to poke around with. – Mathias Jan 10 '20 at 15:33
  • I already push it anyway, it'll be onlise in 2 or 3 minutes after the build. – WilChrist Jan 10 '20 at 15:33
  • Also, may not be connected. You are throwing an error in one of your compiled javascript files. TypeError: Cannot read property 'slice' of undefined – Mathias Jan 10 '20 at 15:44
  • yes @Mathias but the thing is that the app seems to work very well as a PWA app despite what lighthouse is saying.i even tried to understand how lighthouse test this, but i still don't see where the problem come from. – WilChrist Jan 10 '20 at 15:52
  • There is a server redirect somewhere. on a secondary load something is redirecting to `http://quotesaboutjesus.netlify.com/quotes` (note the `http://`) which the server is then redirecting back to `https://`. – abraham Jan 14 '20 at 16:47
  • Hi @abraham. Thanks for your help – WilChrist Jan 15 '20 at 17:51
  • How do you know about this redirection? – WilChrist Jan 15 '20 at 17:52
  • Is it possible that it's angular redirecting from / to /quotes that cause that? – WilChrist Jan 15 '20 at 17:53
  • When I have Chrome DevTools open the network tab shows a 307 redirect before the 200 ok. I'm not sure what causing that initial redirect to the insecure site. It could be an Angular redirect or maybe Netlify. `/quotes` is the path for both requests so the only difference I see is the protocol. – abraham Jan 16 '20 at 03:45

1 Answers1

1

I had this issue too, then I found this solution in : https://stackoverflow.com/a/61152966/8581106

you should add registrationStrategy: "registerImmediately" to serviceWorker registeration in app.module:

ServiceWorkerModule.register("ngsw-worker.js", {
            enabled: environment.enableProdMode,
            registrationStrategy: "registerImmediately"
}),

as mentioned in

Jalaleddin Hosseini
  • 2,142
  • 2
  • 25
  • 28