Choosing Asynchronous jQuery AJAX to Keep the UI Responsive
Guide to configuring jQuery AJAX calls asynchronously, avoiding UI thread blocking, and migrating away from deprecated synchronous requests.
23 Apr 2026, 16:55 UTC

Desired Outcome
Configure jQuery AJAX calls so the browser’s UI thread remains free while network requests are in flight. This prevents page freezes, improves perceived performance, and avoids deprecated synchronous behavior.
Prerequisites
- jQuery 3.x or later (synchronous
async: falseremoved in 3.0). - A local or remote endpoint that can simulate latency (e.g.,
/api/delay?ms=2000). - Basic familiarity with browser developer tools (Console, Network, Performance tabs).
- Permission to serve static HTML/JS files (any static server works).
Procedure
1. Use the default asynchronous setting
jQuery’s $.ajax() defaults to async: true. Explicitly setting it clarifies intent and makes code reviews easier.
$.ajax({
url: '/api/data',
method: 'GET',
async: true, // default, but shown for clarity
dataType: 'json'
}).done(function (response) {
console.log('Data received', response);
}).fail(function (jqXHR, textStatus, errorThrown) {
console.error('Request failed', textStatus, errorThrown);
});
2. Replace legacy synchronous calls
Old code may contain async: false. Refactor to use promises or async/await with the returned jqXHR object.
// Legacy (blocks UI)
var result = $.ajax({ url: '/api/data', async: false }).responseJSON;
// Modern (non‑blocking)
function fetchData() {
return $.ajax({ url: '/api/data', async: true });
}
fetchData().done(function (data) {
// handle data
});
3. Leverage shorthand methods
$.get() and $.post() inherit the asynchronous default, so they are safe to use without extra configuration.
$.get('/api/items', function (items) {
renderList(items);
});
4. Handle cross‑origin requests
For CORS requests the browser forces asynchronous behavior regardless of the async option. Ensure the server responds with appropriate Access‑Control‑Allow‑Origin headers.
Verification Steps
- Create a test page – Save the following as
test-ajax.htmland serve it (e.g.,npx serve .or any static server). - Add a delayed endpoint – A simple Node/Express route:
app.get('/api/delay', (req, res) => { const ms = parseInt(req.query.ms) || 2000; setTimeout(() => res.json({ ok: true, waited: ms }), ms); }); - Run the asynchronous version – In the page, call
$.ajax({url: '/api/delay?ms=3000', async: true}). Open DevTools → Performance, start recording, trigger the request, and observe that the main thread stays idle (no long yellow blocks). - Run the synchronous version (if your jQuery version still permits it) – Change to
async: false. The UI will freeze for the delay duration; the Performance tab shows a long “Scripting” block on the main thread. Modern jQuery (≥3.0) will throw an error:“Synchronous XMLHttpRequest on the main thread is deprecated”. - Check the Console – Look for jQuery’s deprecation warning:
“jQuery.ajax() synchronous request is deprecated”. This confirms the library’s stance.
Limitations and Recovery Options
| Scenario | Impact | Recovery |
|---|---|---|
| Legacy codebase stuck on jQuery 1.x | Synchronous calls still work but block UI. | Plan a migration to jQuery 3.x; wrap sync calls in a Web Worker if immediate migration isn’t possible. |
Third‑party plugin forces async: false | UI freeze persists. | Fork the plugin, replace the call with a promise‑based version, or load the plugin in an iframe to isolate the main thread. |
| Server latency spikes | Even async requests can appear slow if the UI waits on .done() for rendering. | Show a loading indicator, implement request timeouts (timeout: 5000), and consider fallback cached data. |
Practical Checklist
- All
$.ajaxcalls explicitly setasync: trueor omit the option. - No
async: falseremains in the codebase (search forasync:\s*false). - Console shows no jQuery deprecation warnings during typical user flows.
- Performance recordings show no main‑thread blocking > 50 ms during network requests.
Following this guide ensures your jQuery AJAX usage stays compatible with modern browsers, keeps the interface responsive, and aligns with the library’s current best practices.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.