Reputation: 707
I'm having difficulty on some websites I work on with slow executing jQuery $.ajax
.
I am not talking about the server taking a long time to respond. I am talking about the actual execution of the $.ajax
function taking a long time.
Normal (fast) example
Going to jQuery.org and running the following code takes 3ms:
var start = (new Date()).getTime();
$.get("https://jquery.org/projects/")
var end = (new Date()).getTime();
console.log("executed in " + (end - start) + "ms")
Bad (slow) example
However, running very similar code on a demo website I'm working on takes 324ms:
var start = (new Date()).getTime();
$.get("http://sauce-demo.myshopify.com/collections/frontpage/products/bronze-sandals")
var end = (new Date()).getTime();
console.log("executed in " + (end - start) + "ms")
Now obviously the response from $.ajax
(and therefore $.get
) is going to be async. But what could be causing such a huge increase in execution time?
Thanks
Upvotes: 3
Views: 4931
Reputation: 707
Thanks for all the awesome comments guys. You're absolutely right - it looks like there was a global async: false
set up nested in one of the JavaScript files:
jQuery.ajaxSetup({
async: false
});
I wasn't aware jQuery had a global async setup.
Upvotes: 4