Reputation:
I'm currently rendering a handlebars templates to display pages on my node server. I've set the view engine to handlebars
res.render('product', vars);
However, I would like to run the compiled HTML template through juice2 so that the styles are inlined. Because the page is rendered on request, I cannot format the HTML before being sent to the client.
Is there any way of rendering the template server side (to a variable preferably, formatting the content in juice2 and then outputting them)
Upvotes: 0
Views: 552
Reputation: 2528
You can do something like this:
res.render('product', vars, function(err, html) {
juice.juiceContent(html, options, function(err, finalHTML) {
res.send(finalHTML);
})
});
// options.url = base domain like http://example.com
References:
Upvotes: 1