Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Passing streaming of Http response to a web page using node.js

Passing streaming of Http response to a web page using node.js

Problem

Following up on this question I was wondering is there is a way, without using socket.io, to avoid the buffering of the Response that happens on most navigators. So for instance if the node server emit every 5 secondes : 'hello world' i can directly print them on a webpage as soon as the data is available.

Is there a way to do so ?

Problem courtesy of: silkAdmin

Solution

Unfortunately, this is not how web browsers work. If you want this type of functionality without using WebSockets (or a socket.io fallback) you could try with Server-Sent Events. See this gist for an example (in coffeescript). Also, here is a polyfill for older browsers.

Solution courtesy of: Linus Gustav Larsson Thiel

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Passing streaming of Http response to a web page using node.js

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×