Hi, I’m trying to figure out a problem I’ve got on a site I developed. I have more or less the exact same front and back end code for another site which has similar functionality, but this site doesn’t have the same issue. Each site has a project portfolio page with paginated results - clicking on pagination links loads the new content via AJAX, fading one set of projects out and the next ones in. Everything seems to be set up identically but for some reason the pagination works much more slowly on this site, than it does on [URL=“http://maguiresonline.co.uk/projects”]this one. Checking the results shows similar that the Content-Length of the data for each site is pretty similar (both are gzipped), so something is causing the data to be loaded more slowly on one site than on the other. The JQuery code to load and fade in the data is identical.
Can anyone see why this might be happening? Both sites are hosted on the same server and use similar db queries to retrieve the data, there is nothing in the db profiling i’ve done to suggest there is a problem there.
measure how long the serverside code takes to execute.
measure how long the clientside code takes to execute.
compare both sites. This will tell you which side is the culprit.
Once you have determined this, you can narrow your tests to smaller sections of the offending code body. Repeating this process a few times will take you right to your problem.
In javascript, you can use the Date() object and the getTime() method to make a timestamp. Make one immediately before the ajax request is sent, and make another after the response is received and processed. Subtract them to find the elapsed time.
Do the same serverside, but just measure the complete start/end of the script.
Thanks crmalibu. I managed to narrow it down to server side code and to my main controller. This controller does all the general set up (main menu etc) for the pages on my site, then all other controllers extend it. Through bad design, I had included calls to twitter and last_fm in this controller, even though my projects page does not use this data. The api calls were the reason for the slow ajax response. This is more of a PHP design issue now, but I think I’ll strip the main controller down to basics, then extend it with another controller which handles the api calls to twitter/last_fm. Controllers which don’t need the api calls can just extend the main set up controller. Does that seem like a reasonable approach?