$.ajaxSetup Global Defaults or $.when Deferred Aggregation for jQuery Upgrade Recovery
0 reputation · 02 Jul 2021, 21:10 UTC
Global AJAX defaults or deferred aggregation after a jQuery upgrade
The goal is to recover AJAX error handling safely after upgrading jQuery without breaking unrelated scripts on the same page. One option is $.ajaxSetup to set timeout, headers, or error handling globally; the other is $.when to wrap multiple jqXHR objects and handle failures through a single deferred.
$.ajaxSetup applies to every subsequent AJAX call, including third-party code, and does not cancel in-flight requests. $.when offers coordinated retry through a unified .fail handler, but nested rejections can hide which request failed first. Assuming a current stable jQuery release with Promise-compatible jqXHR, the choice depends on whether recovery should be centralized globally or scoped to the upgraded feature.
- Does $.ajaxSetup risk altering third-party AJAX behavior after the upgrade?
- Can $.when preserve the original rejection reason when one deferred in the group fails?
- Which approach isolates recovery logic to the upgraded feature without global side effects?