I’m really interested on how facebook loads only content when someone else has posted something. The only thing that I can think of is using something like the one below to constantly update the page without reloading the page.
setInterval(ajax_stuff, 1000);
I was watching the console and indeed the request occurs and another new content is added to the page.

I want to be enlightened on how is this done. It would really be awesome if I can use this on a project. I mean doing setInterval every second really consumes much resource. Making a request only when its needed would be the best way to do things. Specifically I want to use it on this project:
https://github.com/anchetaWern/ChatRo
It’s basically just a chat box, currently it still uses the setInterval(). I want to update only the content when someone else on the chat session has actually entered something.
I cannot speak directly to how FaceBook does this, but in general, you should be looking at WebSockets.
WebSockets allow the JavaScript on your page to maintain an open connection with a server whereby you can push data out in near-realtime to all of the clients connected to the server.
Take a look at http://pusher.com
Also, google Web Sockets.