-2

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.

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Lucas
  • 16,930
  • 31
  • 110
  • 182

4 Answers4

2

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

Manigandan Arjunan
  • 2,260
  • 1
  • 25
  • 42
0

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.

Arvind Bhardwaj
  • 5,231
  • 5
  • 35
  • 49
0

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.

WebMoss
  • 1
  • 3
0

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

Gabriel Lupu
  • 1,599
  • 1
  • 12
  • 16
  • yes, thank you, but how would I use that in a blog? Could you provide an example please? – Lucas Jan 23 '13 at 23:37
  • In any case, you should have a PHP file (the event source) that checks for upadates in the database - (probably you can set a timestamp in your javascript for the latest post and send it in request. In the PHP file the selection being done on posts that have a higher timestamp than the one received so the return will consist in the newer posts, and then update javascript timestamp) – Gabriel Lupu Jan 25 '13 at 11:27