I have a couple of XHR requests, which are handled by the Mootools Request class. This class offers some options to time the requests appropriately. What I’m doing:
- XHR: Post form data
- XHR: Refresh main pane
- XHR: Refresh subpane
Of course, requests 2 & 3 must wait before 1 is finished. So these are triggered within the onComplete event handler. However, the Request class offers options for handling multiple XHR requests. My question is about these two:
-
The option
linkcan be set tochain, in order to ‘chain’ them, or, as the Moo docs state:Any calls made to start while the request is running will be chained up, and will take place as soon as the current request has finished, one after another.
-
The option
asynccan be set tofalse, to prevent later requests from executing. According to the Moo docs:If set to false, the requests will be synchronous and freeze the browser during request.
Apart from the browser freezing part, what is exactly the difference? Which one should I use for request no. 1? Is it better to do it synchronously, so I’m sure nothing else executes in the meantime? And how about using both, does that make any sense?
well. the difference between link: chain and async: false is simple.
first axiom – you are reusing your request instance and not making a new one. even if you are not, it can work with async. eg, if you have
async: false, then this code:if you go with chain: