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?
- We have a domain → https://example.com
- scripts is hosted at a subpath → https://example.com/assets/myScript.js
- myScript makes a GET call to an external end point - https://foobar.com/
Whats the issue?
- When I visit the forums for the first time (or hard refresh), a single request is sent from the browser.
- 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 - workbox/fetchWrapper.mjs at 194cdeb63d5abb21490f88f01f02f4bcf7e6d54b · GoogleChrome/workbox · GitHub
discourse/service-worker.js.erb at master · discourse/discourse · GitHub - This is the configuration responsible for creating service workers. It uses Network first strategy.
How can we fix this?
Just like auth discourse/service-worker.js.erb at master · discourse/discourse · GitHub - 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.