Does the while loop block ajax from sending requests?

1. Look at this code, vuejs"s code, and execute the following code

in mounted
mounted(){
            console.log("axios send",new Date().getTime())
            axios.get("http://localhost:3000/api?a=2")
            var a=10000000000;
            console.log("while exec",new Date().getTime())
            while(a>0){
                a--;
            }
            console.log("while finish",new Date().getTime())
        },

I received the request at the breakpoint of the background server and found that the time to receive the request was when the while finish code was executed, that is, the request was sent after the execution of the while loop. Why did the while loop block the browser"s Ajax thread from sending the request? Shouldn"t these two not affect each other?

Dec.11,2021

is it possible to try a complex hash operation because the while operation time < request network transmission time?


after self-testing, it is found that if not sent by axios, the request is sent at the right time, that is, before while execution, and because axios uses promise to wrap the xhr request, the task is placed in the micro-task queue, because the micro-task queue will not be executed until all Synchronize tasks have been executed. Request delayed

Menu