What would be the best way to fetch new content on a website with json, I got the following system in my mind: (looped)
- client -> (do i have new content) -> server
- client <- (nope) <- server
- client -> (do i have new content) -> server
- client <- (yes, contentId x) <- server
- client -> (get content with id x) -> server
- client <- (Jim Morrison) <- server
Is this the best way? The application will be used for over 10000+ users, how does Facebook do this, and still keep everyone super fast up-to date?
One modern way to do this is to use a server-push system like WebSockets or Socket.io rather than a client-pull system like occasionally requesting an “is there something new” status.
With this type of technology there is an open connection from the client (I’m assuming it’s a web browser) to the server at all times, and whenever something happens on the server, the server pushes the data out to the client directly.
For code and examples check out http://socket.io/
Not all server-side technology is compatible with this type of approach, but one very good one is Node.js which allows you to write event-driven server-side code in Javascript. See http://nodejs.org
If you choose to use Node.js on the server and want to interact with browsers, there is even Now.js (see http://nowjs.com/ ) which allows you to in effect call functions on the client from the server!