Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Chrome show duplicate HTTP requests when using the angular service-worker?

When chrome makes HTTP requests with the angular service-worker enabled, I see something like this in the Chrome network tab:

enter image description here

  • Why does the chrome network tab show two requests for each request made, one fetch, one xhr? (I only see one request on the server)
  • Why is there no response data for the fetch request?
  • Is the duration and size of each request accurate?

I'm following the official service-worker guide and I'm on the latest Angular 9.

In firefox I do not see the duplicate requests: http://localhost:8080/

Chrome version: 81.0.4044.129

Firefox version: 76.0

like image 798
shusson Avatar asked Nov 07 '22 08:11

shusson


1 Answers

Service worker is handling this request, it's like proxy. The original request is dismissed. This is happening because SW is caching responses (like images, styles or routing) for better performance - instead of downloading resources all the time from server (but this can be changed in Service worker configuration), SW is serving them from browser cache. It's working even if user is offline - that's why routing is working, because service worker is serving html from cache and it's possible to reach the site

like image 88
Damian Plewa Avatar answered Nov 15 '22 12:11

Damian Plewa