Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does gmail use ajax?

Looking at firebug, gmail sends GET requests to get something like:

while (true); &&&START&&&{"Success":true,"Body":{"Contacts":"[[,[,,\"83473f5sc6b17e0\",,[[,1,\"1\"]\n]\n[,,,[,,[,[,,,,,,,,,,,[[,1]\n
...
} &&&END&&&
  • What are these arrays? Are these some sort of RPC?
  • How are they consumed by the client code? More specifically, how would closure library use them?
  • What is the advantage of this approach over plain json and REST?
like image 278
ali Avatar asked May 18 '26 15:05

ali


1 Answers

Looks like ordinary JSON, most likely a response to a RPC, but with the body encoded in some way (probably to reduce the size and therefore bandwidth usage). The while (true); bit is to avoid cross-site access to the data using a script tag pointing to the RPC endpoint - by crashing the script before it reaches the juicy private information it can prevent evil sites from using the data. Parsing instead would use JSON.parse or similar, after stripping off everything outside the start and end tags.

This kind of compressed encoding can be helpful if you are running a huge site like gmail, and have control over the client side. REST is however very useful for third-party developers, as it's easier to debug (and document!). The while(true) bits, however, are essential for any API that allows GET and carries sensitive data in the response.

like image 131
bdonlan Avatar answered May 20 '26 06:05

bdonlan



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!