Tuesday, March 15, 2011

Be persistent: if it fails, try again

Do you remember the last time you loaded a web page, the page started to load, but then stalled… after a little while, you hit that reload button, and the page showed up just fine. The browser reload button puts you in control when page loads don't go through. But what about Ajax requests?

You can't manually tell the browser "retry that last Ajax request"; only the JavaScript code that issued the request can, and so it is important that it does. The soon to be released Orbeon Forms 3.9 incorporates an automatic retry mechanism for Ajax requests:
  1. If an Ajax request fails or times out, Orbeon Forms client-side code automatically resends it to the server.
  2. If the request fails multiple time, the delay between each retry is increased (up to a maximum delay). This is done not to overwhelm the server with lots of requests, in case a number of clients experience failures at the same time, and then all the retries reach the server around the same time, for instance because a connection is reestablished.
  3. Imagine an Ajax request makes its way to the server, is executed by the server producing some side effect (for instance updating a database), but the corresponding Ajax response fails to get back to the browser. In that case, you would like the browser to be able to resend the request, and the server to resend the Ajax response it produced earlier without executing it again. Lucky us: this is exactly what happens with Orbeon Forms 3.9.
  4. And as a bonus: the same retry mechanism also applies to file uploads.
You don't need to setup anything for this retry mechanism to be active, but should you want to tweak it, see the section Retry mechanism for Ajax requests in the XForms configuration properties.

No comments:

Post a Comment