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?
- 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 - 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.