Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6622669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:26:13+00:00 2026-05-25T21:26:13+00:00

I was curious how facebook can show content live. For example, when one user

  • 0

I was curious how facebook can show content live. For example, when one user comments, another person from somewhere else in the world can see that comment appear right after the user comments.

I know ajax/jquery can do an .append(data) without refreshing the page, but that won’t show on other users. Would it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:26:13+00:00Added an answer on May 25, 2026 at 9:26 pm

    I’m not sure exactly how Facebook does it, but heres how it probably works.

    1. User comments on item
    2. Comment is posted to server
    3. Server processes comment
    4. Server finds who is subscribed to that item (post, image etc.) and pings them with a notification of a new comment
    5. The other clients (ones who didn’t post the comment) request a page which returns the number of comments
    6. They compare there comment count with FB’s comment count. If they aren’t the same, request new comments

    See https://www.facebook.com/notes/facebook-engineering/inside-facebook-messages-application-server/10150162742108920

    EDIT:

    To go in deeply with what function you should use.
    Firstly you have a list of comments.

    <ul id="comments" style="list-style-type: none;">
    
    </ul>
    

    I set the list-style-type to none so the bullets would not show.

    When the page loads, you use a jquery AJAX function, to perform a HTTP GET Request to the page serving comments. You then inject them into the DOM, using

    $('#comments').html(loadedAJAXData);
    

    Where loadedAJAXData is the data you got from a GET request.

    So the injected data looked like this –

    <li>Comment 1
    <li>Comment 2
    <li>Foo
    

    and now the comments list looks like this –

    <ul id="comments" style="list-style-type: none;">
    <li>Comment 1
    <li>Comment 2
    <li>Foo
    </ul>
    

    So you have your comments now. Someone makes a new comment? It is sent to your website, which inserts a new comments row into the database.

    Say you have another page, which you request the number of comments from. Lets call it comments.php?count.

    // set interval
    var tid = setInterval(getCommentsCount, 2000);
    function getCommentsCount() {
    //AJAX will request comment count from comments.php?count . 
    //Comment count is stored  in the variable newCommentCount. Previous or cached comment //count is stored in oldCommentCount.
      if(oldCommentCount != newCommentCount){ //If we have a different number of comments
        for(int i = oldCommentCount;i<newCommentCount;i++){
           //For each new comment
           //Make a request to comments.php?get=commentOffset
           //Then inject it into the DOM using
           $('#comments').append(comment);
           oldCommentCount++;
           }
      }
      // no need to recall the function (it's an interval, it'll loop forever)
    }
    

    For example, in this script, the browser is requesting comment count every 2 seconds. Our oldCommmentCount was 0. Our newCommentCount is 2. For each new comment, we will make a request to comments.php?get=commentOffset. Where commentOffset is i. Requesting the new comment, we get its data, append it to the comments list, and then increment oldCommentCount.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A friend of mine downloaded some malware from Facebook, and I'm curious to see
Curious about user notification techniques. Referring to simple stuff. For example, a user submit's
Curious question. I'm using Microsoft's Sandcastle to generate documentation from the XML comments in
Curious, what happens when you return keyword this from a struct in C#? For
just curious when you post a link to facebook they seem to parse out
Curious, if I can invoke some 3rd party activity, and then in onActivityResult read
I'm doing some work with the new Facebook js library, http://github.com/facebook/connect-js . There's one
I'm really curious how Google (and now Facebook in the photo galleries) implemented shortcut
I've asked this on the Facebook Developer Forums, but no-one is answering, so thought
I am curious to know how can i add the Open ID login to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.