I want to display a user's latest Tweets on a webpage while maintaining the ability to style the Tweets with custom CSS and also maintaining good page load speed.
I have managed to display the latest Tweets in 2 ways.
Using the PHP Twitter library (by Aaron Brazell). By using this method, my PHP code has to wait for a response from Twitter before my page can be pleted and sent to the client. This could cause the page load time to be quite unpredictable and more than likely slow down the page load enough to be annoying to users.
Using the Blogger Twitter Widget, the latest Tweets are loaded using JavaScript after the rest of the page has loaded. This way user's don't have to wait for Twitter response before they can view the page.
I would like to know if there are any other pro's and con's to using these different methods to display a user's latest Tweets, and also if there is perhaps another solution I can look into which will enable custom CSS styling and provide good page load performance?
Also, how do these 2 methods influence the way Twitter applies Rate Limiting? Using PHP I can cache the Tweets and therefore make fewer calls to Twitter, while using JavaScript this is not possible as far as I know?
I want to display a user's latest Tweets on a webpage while maintaining the ability to style the Tweets with custom CSS and also maintaining good page load speed.
I have managed to display the latest Tweets in 2 ways.
Using the PHP Twitter library (by Aaron Brazell). By using this method, my PHP code has to wait for a response from Twitter before my page can be pleted and sent to the client. This could cause the page load time to be quite unpredictable and more than likely slow down the page load enough to be annoying to users.
Using the Blogger Twitter Widget, the latest Tweets are loaded using JavaScript after the rest of the page has loaded. This way user's don't have to wait for Twitter response before they can view the page.
I would like to know if there are any other pro's and con's to using these different methods to display a user's latest Tweets, and also if there is perhaps another solution I can look into which will enable custom CSS styling and provide good page load performance?
Also, how do these 2 methods influence the way Twitter applies Rate Limiting? Using PHP I can cache the Tweets and therefore make fewer calls to Twitter, while using JavaScript this is not possible as far as I know?
Share Improve this question edited Jan 20, 2010 at 10:12 sizeight asked Jan 20, 2010 at 10:02 sizeightsizeight 7391 gold badge9 silver badges19 bronze badges8 Answers
Reset to default 10You can have custom CSS styling in both ways, so this shouldn't be a problem
when using PHP api, try to cache all the info you need and put it in eg. Database (and query twitter every 5-10 mins., or run update script through cron - since I last checked there is a limit on queries in twitter you can perform on a specific time basis)
by using Javascript to update tweets you disable web spiders to index these tweets on your page (also disabled people usually don't have JS enabled... )
EDIT
Also note, that you will need more PHP coding to implement caching, but this is a very nice coding experience (on the other hand it is easy to implement a JavaScript script to fetch such things as updates from twitter)
Twitter API Rate Limiting
As read on twitter.api: Twitter limits REST requests to 150 requests/hour (using IP based rules or counting requests for authenticated API usage)
GET requests like fetching twitter feeds, timelines through rest api do count
POST requests like updating statuses do not count
Account rate limit status available at http://twitter./account/rate_limit_status.format
where you can check how many request you can do in specified time limit
Pro: Absolutely independent from users' settings. Con: What you said - if Twitter is slow, your site is slow + an extra lot of requests from your server -> increased server load etc.
Pro: Less work for your server - load speed is only dependent on your server's speed. Con: Not everybody has JavaScript enabled and even then you might have an ugly delay in the Twitter stuff popping up.
I'd go for option #1, personally.
try using sweetcron. you can make it a cron job. It will fetch Twitter feeds and put them into database. so twitter refrence will not affect your pageload.
more details here: http://code.google./p/sweetcron/
My opinion - do in in client side.
- Why wasting you CPU time on this? Let the client handle this.
- Google will index it, and when the user browses there he will see something different.
I'd go for a more flexible and stable approach:
Check for new tweets repeatingly in the background (eg. every 5 minutes) and store them in your database. So you have all your tweets on your own server. This also prevents your site from loading for ages when twitter is down. Not to mention it's also working when JS is disabled ;)
Con here is the delay, but you could decrease the sleep-time, but in fact I think 5 minutes is more than short enough.
When your visitor has JS enabled and you want it to be feeling a bit more live, you could update your tweet using some AJAX.
I can't really add anything to what's been mentioned already.
PHP would be the best way to go, but do make sure you cache the results at regular intervals. You could simply parse your Twitter profile's RSS feed with any of PHP's built-in XML/DOM tree parsers to output in whatever format you need, and this style however you wish.
The disadvantage of using a JavaScript method to display tweets is, as aforementioned, it will not be crawled by search engine spiders and will not work for visitors with JavaScript disabled (naturally).
Both, build the tweet list using PHP then have a simple jQuery plugin (or something similar) running client-side to keep it up to date.
- Works for clients without JavaScript
- Allows you to implement server-side caching
- Google will index it (which might be good?)
On my site, my solution is to load the page as normal, and then include some tickers to show that there is data still to e. I then have a PHP script accessed with AJAX that loads the data from Twitter and outputs it in a nice way - I haven't implemented caching because I have an extremely low volume of traffic, but I could in the future. I also have a <noscript>
tag with an iFrame for those unusual people who are without Javascript!
I choose this method because it allows me to let the user see the page very quickly, but they can still see the tweets later.