What would be the quickest, most efficient way to reload content on a blog page once change has been detected?


I want to create a blog, which I want to be very user-friendly, and I want the most efficient way to display recent blog posts.

For example, one might want to programmatically reload a div every 5 seconds or so, or they might send a request every 10 milliseconds to a page, which checks for changes in the content of the blog (i.e. if someone else has posted), and then reload the div containing the blog contents once change has been detected.

And what other ways are there? Which one does Twitter or similar services use? Is there's one I'm missing?

UPDATE: It seems AJAX really can't work, and I'll need something along the lines of node.js or something similar, if you can, please help in that direction please.

Problem courtesy of: think123


You can use APE(Ajax Push Engine), socket.io or node.js for this. You can also use comet in php

Solution courtesy of: Manigandan Arjunan


Repeated AJAX requests is the worst way of doing it. You must read about node.js to make the push requests from server.

Twitter/Facebook use the server side push requests to update the user's screen.

You can also look at Pusher which provides API for real time page updates. See the example.

Discussion courtesy of: Arvind Bhardwaj

I think AJAX would be your best solution, it will provide the user with a good look & feel when it is loading newer posts, dynamic which is what I think you want to achieve.

You could then customize your return data, so for example, you could check for any newer posts by comparing if an id greater than the current post(this will depend on your database setup for the blog) and then only return those newer posts and then append them to your posts display div using jquery or javascript, or you could reload the last 5 or 6 posts which is normally done with some form of pagination.

You can then setup a poll function to trigger the AJAX event every 10 or 15 seconds.

Discussion courtesy of: WebMoss

You might want to take a look at (HTML5 server-sent events). Unfortunately there's no support for IE ...

Discussion courtesy of: Gabriel Lupu

This recipe can be found in it's original form on Stack Over Flow.