0

I'm serving a one page app. The app always needs to request initial data from the server once it's loaded.

Is there anyway to dynamically serve data with the initial asset load of css/html/javascript, without rendering it in the html?

Sending a js object with the data so we don't need to ping the server?

inserting a script tag? adding a dynamically created js file to the asset load?

A little bit lost, any help would be really appreciated.

boom
  • 10,856
  • 9
  • 43
  • 64
  • Do you need to *request* it at pageload? Otherwise, you could just embed it into your HTML page as a Javascript object [as explained here](http://stackoverflow.com/questions/7681821/passing-objects-to-client-in-node-express-jade). – robertklep May 18 '13 at 19:16

1 Answers1

0

In my opinion, the best way to serve dynamic content from the Node.js server to the client is to use socket.io.

If you don't wanna use socket.io, you can try to create a dynamic page that acts different on the Node.js server, and use XMLHTTPRequests to receive the data.

dylanweber
  • 580
  • 7
  • 19
  • I'm using socket.io, you still have to wait for initial connection and then send the data. That's the extra round trip I'm trying to avoid. – boom May 18 '13 at 19:39