Javascript slow-load technique
I'm trying to learn all i can about the slow load technique (as described here: http://www.obviously.com/tech_tips/slow_load_technique) in javascript, for making near-realtime chat applications and the like.
I know facebook uses it too, for its chat. It first calls this url: http://0.1.channel.facebook.com/x/a_bunch_of_parameters which lingers a long time, with connection: keep-alive. Then it suddenly returns with this javascript:
for (;;);{"t":"continue"}
I'm not logged in into the chat, so it obviously doesn't include any chat data, but i'm wondering what the surrounding javascript that processes the result would look like. Probably it parses the json and sees the t-key has the value of continue. What would the infinite for-loop accomplish thou开发者_开发知识库gh?
The facebook page has a huge javascript callstack, so i can't plough through it. Can someone guess or does someone know? Thanks in advance!
see here: How to restrict JSON access?
The infinite loop is a measure of protection from outside sources calling the script. If I want to call that link from my site, i'd have to do it with
<script src="http://0.1.channel.facebook.com/x/a_bunch_of_parameters"></script>
which would immediately start the infinite loop. I couldn't get at the actual message facebook has returned.
facebook can use a XMLHttpRequest to pull from that address and parse out the infinite loop code before evaluating the response message. I can't do that from my site because of cross-domain security.
For facebook's use, the message could be something like
for (;;);
{
"msg" : {
"from" : "lincolnk",
"content": "derp!"
}
}
they would parse out the javascript object which contains whatever the other person wrote and dispaly it to you.
精彩评论