admin管理员组

文章数量:1379528

When using jade-lang on production, would I benefit from having some form of a middleware that pre-piles all the .jade views and then uses them in res.render? Or does that automatically happen when you do NODE_ENV=production?

I'm simply exploring options on how to speed-up jade rendering on production.

When using jade-lang on production, would I benefit from having some form of a middleware that pre-piles all the .jade views and then uses them in res.render? Or does that automatically happen when you do NODE_ENV=production?

I'm simply exploring options on how to speed-up jade rendering on production.

Share Improve this question asked Mar 6, 2014 at 9:55 TheThingTheThing 1591 silver badge11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

When Jade piles the template, the template is cached. In production environment if you warm up the cache, then there is no need to pre-pile template. Even if you don't, the template will be cached after its first pilation.

I remend you to have a look Jade's source code to better understand how it works.

exports.render = function(str, options, fn){
  // ...
  var path = options.filename;
  var tmpl = options.cache
    ? exports.cache[path] || (exports.cache[path] = exports.pile(str, options))
    : exports.pile(str, options);
  return tmpl(options);
};

Source: https://github./visionmedia/jade/blob/1.3.0/lib/jade.js#L255-L259

exports.renderFile = function(path, options, fn){
  // ...
  options.filename = path;
  var str = options.cache
    ? exports.cache[key] || (exports.cache[key] = fs.readFileSync(path, 'utf8'))
    : fs.readFileSync(path, 'utf8');
  return exports.render(str, options);
};

Source: https://github./visionmedia/jade/blob/1.3.0/lib/jade.js#L291-L295

本文标签: javascriptWould it benefit to precompile jade templates on production in expressStack Overflow