8

OK, I am using javascript sever side, including node.js. Because of performance issues, we have decided to move one page to being rendered server-side, not client side, so the server returns a stream of html, fully rendered, back to the client.

I have seen this question and the related answers, but wondered if this was the best or right approach. In particular, what is the most appropriate way to render a page, and run all of the javascript on it within a js or node.js call?

Ideas that I have looked at:

  1. Call the javascript code directly on the page, and invert everything to make it generate the html items needed. As this is urgent, I would rather avoid re-writing any more than I have to.

  2. Render a document, with a simple iframe to generate the html. But how do I point to the page in the iframe, as I am server side? Surely this is just adding another level of abstraction to the same problem.

  3. Using the ideas detailed above, but I am wondering whether this is the right route, given some of the problems I have seen encountered with it.

EDIT: Just to clarify - I want to, in effect, load the html page in a browser, let it finish rendering, and then capture the entire generated html for passing through to the client (saving the time to render on the client).

Community
  • 1
  • 1
Schroedingers Cat
  • 3,099
  • 1
  • 15
  • 33
  • you may use ajax and getscript method in jquery to render and evaluate javascript. have look at this link http://api.jquery.com/jQuery.getScript/ – Bhushan Kawadkar Aug 28 '13 at 11:21
  • Did you want to do something like what is demonstrated here? [link](https://github.com/FissionCat/handlebars-node-server-example) – Timespace Aug 28 '13 at 12:29
  • @Timespace - that is looking like a good direction to be going in. Thank you. Other suggestions are still welcome. – Schroedingers Cat Aug 28 '13 at 15:41

3 Answers3

2

There's some pretty useful documentation found here: http://www.hongkiat.com/blog/node-js-server-side-javascript/

Like you said, avoiding lots of rewriting is a bonus.

user5623896726
  • 136
  • 1
  • 11
2

This is a simple example that does server-side templating (no express): https://github.com/FissionCat/handlebars-node-server-example

This is an example that serves html, js, css and an mp3 (but doesn't use express or any templating): https://github.com/FissionCat/Hue-Disco

Timespace
  • 508
  • 4
  • 18
-2

Might be the information provided in the article be of some help.

Rachit M Garg
  • 263
  • 4
  • 19