Duplicate requests in Chrome

Hello Team,

Our team is handling discourse forums and its experiencing issues of duplicate requests on Chrome and not on Firefox or Safari. I suspect this issue to be related to service workers - workbox.

What does the setup look like?

  1. We have a domain β†’ https://example.com
  2. scripts is hosted at a subpath β†’ https://example.com/assets/myScript.js
  3. myScript makes a GET call to an external end point - https://foobar.com/

Whats the issue?

  1. When I visit the forums for the first time (or hard refresh), a single request is sent from the browser.
  2. Upon second request, two requests are sent from the browser. One from the file which is served from the service worker and one from fetchWrapper.mjs - https://github.com/GoogleChrome/workbox/blob/194cdeb63d5abb21490f88f01f02f4bcf7e6d54b/packages/workbox-core/_private/fetchWrapper.mjs#L111

Additional Information:
https://github.com/discourse/discourse/blob/master/app/assets/javascripts/service-worker.js.erb#L18-L35 - This is the configuration responsible for creating service workers. It uses Network first strategy.

How can we fix this?
Just like auth https://github.com/discourse/discourse/blob/master/app/assets/javascripts/service-worker.js.erb#L10 - we can expose /analytics/ as a route or make it configurable for users to pass an array of custom routes which is set to NetworkOnly. Our setup is on Docker and EC2, so this should be exposed there as well.

1 Like

Are you sure both requests are hitting the actual network? The second is likely being used to respond to the first.

3 Likes

Yes. In out setup its happening to our analytics code and thus, analytics data is doubled.

1 Like

Those are not duplicated requests but just a quirk of how Chrome Dev Tools display the service worker proxy.

Also you can check the application logs to see that the server don’t get duplicate requests for any routes, like /latest.json.

So this is not a bug on Discourse.

3 Likes

Thank-You so much team. Indeed this is a Chrome quirk. Chrome is displaying multiple requests while the data has deduped data.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.