@Oliver Here is an example where an asynchronous template engine like dust 
could provide a nice optimization in time to render a page from server to 
browser.

Let's say a dynamic page on the server is rendered from a layout and it 
depends on several pieces of data from the database all of which can vary 
from page to page:

- javascript 
- css 
- main data

I can fetch all of them in parallel from one or more databases and as soon 
as I have the javascript and css, I can start rendering and streaming the 
head, so the browser can fetch and parse, then when the data is ready, I 
stream the rest.

Assuming the javascript and css data can be fetched more rapidly than the 
main data (which could be using a complicated query), then I am not wasting 
time waiting for everything, the browser can be using the time to prepare 
what it has, then when the final data arrives, it can instantly finish the 
render.

Given this template:


<html>
  <head>
    {javascript}
    {css}
  </head>
  <body>
    {mainData}
  </body>
</html>



It can stream the template in chunks from the server to the browser, 
blocking at {javascript} until it has that data, then blocking at {css}, 
then {mainData}. 

So as the data becomes available, more chunks can be delivered to the 
browser. Assuming these are all fetched in parallel and that javascript and 
css return first, we will have a nice optimization by being able to get the 
browser javascript and css to parse, while it is waiting for the main part 
of the page.

It is mostly useful for rendering templates on the server. If you are 
rendering on the client, then you will likely be synchronous.


Jeff

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to