Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anybody explain why Facebook seems to hide HTML code in HTML comments?

While poking around in the Facebook source code, I've stumbled across something I can't explain. If you go to http://www.facebook.com/YOURUSERNAME/allactivity and look at the source code, command/ctrl F and look for the tag:

<code class="hidden_elem"

In the third or fourth one down, you will see the tag containing (what must be) the code generated for the allactivity page.

However, it is wrapped with a HTML comment (<!---->). Can anybody tell me what the benefit of doing this is, and/or how that code is eventually executed? Also, how do they pull that code with ajax? (it seems they generate more based on scroll-downs)

like image 678
dysruption Avatar asked Nov 26 '25 05:11

dysruption


1 Answers

It looks like it is code which is the content of different submenus (on the left). My guess is that when you click on one of the menus, it corresponds to a specific comment's parent container's ID. (On mine, for example, the job history is under the code node with the ID u_0_2a). It then gets the child node and evaluates the innerHTML when the appropriate link is clicked.

My guess is that they do this for several reasons.

  1. It eliminates the need for extra requests to the sever.
  2. Evaluating loaded data is faster than loading new data.
  3. Comments do not significantly effect render time.
  4. If text is commented, then the CSS is simpler (no worries about hiding divs, they simply don't exist).
like image 67
cwallenpoole Avatar answered Nov 27 '25 21:11

cwallenpoole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!