Cross domain reverse ajax working example
Hi, I have found very nice, pro made component of chessboard which enables playing online chess. It can be put on any web, and it comunicates via reverse ajax in realtime cross domain. My question is, how do they do it? As far s I know, reverse ajax is not allowed cross domain.
Check the link: http://www.chessfriends.com/liveGenerator
are there any working libraries for that? I have some php chat server and I want to create something like this chessboard, but for my chat.
Btw, this chessboard is really nice, I will put it into my blog
I suspect they are using AJAX + a server-side proxy application. That would work crossbrowser.
the games don't use ajax at all: no xml, no xmlHttpRequest...
they simply load a script tag (which again can come from anywhere), and the code inside the external script tells the game client how to draw the board.
php kinda sucks for doing this, nginx or node.js would be far more efficient since the only way to update external values in-page in php is through a flat file or db, whereas the other guys can share values while the page is in session.
ok, that's not a coherent explanation, let me try again:
if a php page takes 10 seconds to build due to using sleep(), the only way to have data available at second #9 that wasn't available at second #1 is to load a file or query a DB.
basically, you have to commit the move to a db with one client, then poll the db with the running long-poll page until a change is found.
the performance diff of using node.js is akin to moving from document.write() to div.innerHTML: you don't need a "refresh" from an external data source to make new info available, and many pieces can be updated independently of other pieces.
to wit: in node.js i can load a 20mb json into ram at boot, and every request has access to that big variable using closure from the request event's function to the global variable. php would have to load/parse the same big file every time someone asked for it...
Last edited by rnd me; 07-11-2011 at 05:13 PM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread