ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 382 forks source link

Compile views when Node app is launched & compile when requested #131

Closed MarkusPint closed 9 years ago

MarkusPint commented 9 years ago

I want to be able to manually update the cache of compiled templates. First they should be compiled in the back-end when the Node app is launched and then whenever page content (ie. variables that are passed to the templates) is updated from the CMS.

And then, basically, the client should be served a regular HTML page.

I don't want to compile the views again every time a client requests it.

The goal is to avoid excessive DB requests.

How should I go about doing that?

ericf commented 9 years ago

Handlebars has two forms of compiled templates: compiled for rendering, and precompiled for portability and re-hydrating and rendering somewhere else, like the browser. If you want to use the same templates on the server and in the browser you'll need to compile them twice.

See the Advanced Example for how to do this.