Max Belinskiy
Max Belinskiy

Reputation: 1

Is it possible to make client Javascript to become sync on demand

Why client JavaScript is asynchronous with HTTP requests? Can't it just pass execution flow to interpreter and wait for its call to be picked up from stack and execution to be resumed?

Is it technically impossible to implement?

Upvotes: 0

Views: 37

Answers (1)

Scott Marcus
Scott Marcus

Reputation: 65845

Why client JavaScript is asynchronous with HTTP requests?

If it wasn't, users would have to have their web pages load one resource at a time and page load times would increase dramatically. Who would want that?

Is it technically impossible to implement?

No, it's not impossible, you could load each resource with an AJAX request that was configured for a synchronous call. But again, I ask, who would want that?

In addition to slowing load times, the UI would be blocked (frozen) until the synchronous operations complete. With modern web pages, you would essentially be creating a frozen screen that takes a long time to render and unfreeze.

If you need operations to happen one after the other, use Promises.

Upvotes: 4

Related Questions