Skip to content

Commit

Permalink
Improve jade render speed.
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Nov 23, 2013
1 parent 58fc3e5 commit 3535dc5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/engines/jade.js
Expand Up @@ -37,17 +37,24 @@ function getTemplate(template) {

exports.render = function(template, data) {
init();
if (!store._templates) {
store._templates = {};
}

if (!/\.jade$/.test(template)) {
template = template + '.jade';
}

var filename = getTemplate(template);
if (!filename) {
throw new Error('template ' + template + ' not found.');
}
var fn = store._templates[template];
if (!fn) {
var filename = getTemplate(template);
if (!filename) {
throw new Error('template ' + template + ' not found.');
}

var fn = jade.compile(file.read(filename), {filename: filename});
fn = jade.compile(file.read(filename), {filename: filename});
store._templates[template] = fn;
}

data = _.defaults(data, store.globals);
return fn(data);
Expand Down

2 comments on commit 3535dc5

@kavinyao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is caching compiled templates that makes rendering much faster?

@lepture
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Please sign in to comment.