Proof that even if an XHR is sent in a Web Worker (synchronously), it never gets sent while the main thread is blocked.
Online at: https://azriel.im/worker_sync_xhr/
Output:
21:45:04.769 main: creating worker
21:45:04.828 worker: created
21:45:06.498 ---
21:45:06.504 main (sync): sending message to worker
21:45:06.505 main (sync): wait begin
21:45:08.045 main (sync): wait end
21:45:08.047 worker: request begin
21:45:08.054 worker: request end
21:45:11.884 ---
21:45:11.888 main (async): sending message to worker
21:45:11.889 main (async): wait begin
21:45:11.896 worker: request begin
21:45:11.968 worker: request end
21:45:12.891 main (async): wait end
Logic
main
:
- Start
worker
. - Log begin.
- Wait 1.5 seconds.
- Log end.
worker
:
- Log begin.
- Send XHR synchronously.
- Log end.
-
Start a HTTP server in the repository directory:
python -m SimpleHTTPServer 8000
-
Open http://localhost:8000/.
-
Look at the console log.
-
Edit
index.html
. -
Refresh the page.