What would be the best way to fetch new content on a website with json, I got the following system in my mind: (looped)
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?
To get JSON from the server using the Fetch API, you can use the response. json() method. The response. json() method reads the data returned by the server and returns a promise that resolves with a JSON object.
fetchjson. 1 Comments. JSON, which is a simple format of structured data, has become a popular format to send data over the network. Here's an example of JSON containing an object with props and values: json.
JavaScript Object Notation, more commonly known by the acronym JSON, is an open data interchange format that is both human and machine-readable. Despite the name JavaScript Object Notation, JSON is independent of any programming language and is a common API output in a wide variety of applications.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With