Results 1 to 3 of 3

Thread: Cross domain reverse ajax working example

  1. #1
    Join Date
    Jul 2011

    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

  2. #2
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    I suspect they are using AJAX + a server-side proxy application. That would work crossbrowser.

  3. #3
    Join Date
    Jul 2008
    urbana, il
    javascript can come from anywhere: script tag's .src is not domain-specific.
    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.
    this pattern is called JSNOP, however the game doen't use JSON, but actual raw JavaScript instructions to achieve the same basic thing.

    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.

    with node.js, users of a single game can share a regular JavaScript object in ram, eliminating the need for DBs/files. Additionally, node.js can raise an event on all other game player's connections the instant a change to the game data occurs, which eliminates the need for polling.

    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 06:13 PM.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center