$.getJSON is slow
Question by Abhishek Kumar
I am using $.getJSON
to pull inventory of objects (100 items, not a large set) but its taking 8-10 seconds for XHR call.
Would like to learn if there is something I am missing or something I could do to expedite my program?
Answer by Starx
There are many things involved on it. Two main bottleneck I think are these
-
The server script generating the JSON might be causing the problem or taking long process time to generate the output.
-
You have too many scripts on your page like effect or slider, that the getJSON, is running slow
In most of the cases, the first one is a silent killer. In order to test your script, make a getJSON request to page, which simply displays the JSON string, without any processing. Something very lightweight like this
{ "test" : "value" }
In PHP
echo ‘ { “test” : “value” }’;
And make a getJSON
request to this page and check if the script is running fast. In case it is fast, the problem is in your server script.