Background
Browsing Facebook and being curious, I decided to look through the network XHR
tab in the chrome developer tools to view the API calls they make to their back end. Upon looking at the calls and headers, noticed something very peculiar about how they send and package their data:
for (;;);{
"__ar": 1,
"payload": {
"profiles": {
"1244780025": {
"id": "1355891136",
"name": "JoeD Dirt",
"firstName": "Joe",
"vanity": "joe.dirt",
"thumbSrc": "https://some.picture.url/source.png",
"uri": "https://www.facebook.com/joe.dirt",
"gender": 2,
"i18nGender": 1,
"type": "friend",
"is_friend": true,
"is_active": false,
"mThumbSrcSmall": null,
"mThumbSrcLarge": null,
"dir": null,
"searchTokens": [
"Joe",
"Dirt"
],
"alternateName": "",
"is_nonfriend_messenger_contact": false
}
}
},
"bootloadable": {},
"ixData": {},
"gkxData": {},
"lid": "6440706546668495821"
}
And the content type:
content-type: application/x-javascript; charset=utf-8
It really got me wondering if returning the data as an actual javascript object, rather than a string of JSON is any faster or even more convenient to do, however I am unsure about how to use this type of return.
My questions
- How would I go about using this type of data structure safely? Obviously it returns javascript, but doesn't it need to be ran in an
exec
, which can be unsafe? - How would I go about performance testing this structure against its
JSON
counterpart? - Are there any advantages (performance or otherwise) to using one over the other?
EDIT While Empty "for" loop in Facebook ajax answers9 very poorly, the WHAT about this, it doesn't answer any of the 3 questions I posed above.