Would like some assumption validation and opinions on solutions to a js xhr throttling problem I seem to be running into on Chrome on Android when the phone screen is off (browser tab is in background mode).
My use case is:
- Phone has focus on Chrome browser tab but is asleep (screen off)
- JS Webworker has a setInterval call which sends a msg to the main JS thread ever 10 seconds.
- Main JS thread, upon receipt of web worker msg, issues an XHR request to get a file.
- Files are queried for and received by the main thread for a period of time (5 min?) after the phone’s screen is off
- At some point, file XHR requests begin to fail.
I believe that switching the XHR request into the Webworker will solve my problem. So instead of the Webworker being only the timer that tells the main thread to make an XHR request, the Webworker actually makes the XHR request itself every 10 seconds and then sends the file in a msg to the main thread. Can someone confirm this approach will work?
Kind of a big code change so want to source some opinions before doing it. Thank you.