javascript - How would you create an auto-updating newsfeed without a reload? -


how go around creating auto-updating newsfeed? going use nodejs, told me wouldn't work when got thousands of users. right now, have can post text newsfeed, , save mysql database. then, whenever load page, display posts database. problem have reload page everytime there update. going use tell nodejs server posted update...

index.html

function sendpost(name,cont) {     socket.emit("newpost", name, cont); } 

app.js

socket.on("newpost", function (name,cont) {     /* adding post database      * calling event new post created      * , emit new signal new data */ }); 

but won't work ton of people. have suggestions should start, api's and/or programs need use?

you're on right track. build route on node webserver cause fetch newspost , broadcast connected clients. then, fire request node.

on node-to-client front, you'll need learn how long polling. it's rather easy - let client connect , not end response until message goes through it. handle through event handlers (postal.js worth picking this).

the ajax part straightforward. $.get("your/node/url").then(function(d) { }); works out of box. when comes (either success or failure), relaunch it. set timeout 60 seconds or so, , end response on node front moment 1 event targetted it.

this how sites it. problem websockets that, right now, they're bit of black sheep due old ie versions not supporting them. consider long polling instead if can afford it.

(psst. whoever told node wouldn't work in thousands of users talking through asses. if anything, node more adapted large concurrency php due fact connection on node takes nothing keep alive due event-driven nature of node. don't listen naysayers.)


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -