Can AJAX in a CMS slow down your server

Posted by Saif Bechan on Pro Webmasters See other posts from Pro Webmasters or by Saif Bechan
Published on 2011-11-12T16:23:03Z Indexed on 2011/11/12 18:07 UTC
Read the original article Hit count: 379

I am currently developing some plugins for WordPress, and I was wondering which route to take. Let's take an example, you want to display the last 3 tweets on your page.

Option 1

You do things the normal way inside WordPress. Someone enters the website, while generating the page, you fetch the tweets in php via the twitter api, and just display them where you want.

Now the small problem with this is, that you have to wait for the response from twitter. This takes a few ms. NO real problem, but this is question is just out of curiosity.

Option 2

Here you don't do anything in WordPress on the initial load, but you do have the API inside. Now you just generate the page, and as soon as the page is done on the client side, you do a small AJAX call back to the server via a WordPress plugin, to fetch your latest tweets. Also called asynchronously.

Now the problem with this IMO is that you have much more stress on your server. For starters you have two HTTP requests instead of one. Secondly the WordPress core has to load two times instead of one.

Other options

Now I know there are a lot of other options: 1) Getting the tweets directly via javascript, no stress on the server at all. 2) Cache the tweets so they are fetched from the DB instead of using the API every time. 3) Getting the tweets from an ajax call that is not a WordPress plugin. 4) Many more.

My Question

Now my question is if you only compare 1 and 2, which would be a better choice.

© Pro Webmasters or respective owner

Related posts about web-development

Related posts about optimization