It would be useful to precompile jade patterns for production into express

When using jade-lang in production, I would like to get some form of middleware that precompiles all kinds of .jade and then uses them in res.render? Or does this happen automatically when you do NODE_ENV = production?

I'm just exploring options for speeding up jade rendering in production.

+6
source share
1 answer

When Jade compiles the template, the template is cached. In a production environment, if you are warming up the cache, then there is no need to precompile the template. Even if you do not, the template will be cached after its first compilation.

I recommend that you look at the Jade 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.compile(str, options)) : exports.compile(str, options); return tmpl(options); }; 

Source: https://github.com/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.com/visionmedia/jade/blob/1.3.0/lib/jade.js#L291-L295

+11
source

All Articles