javascript - Would it benefit to pre-compile jade templates on production in express -
when using jade-lang on production, benefit having form of middleware pre-compiles .jade views , uses them in res.render? or automatically happen when node_env=production?
i'm exploring options on how speed-up jade rendering on production.
when jade compiles template, template cached. in production environment if warm cache, there no need pre-compile template. if don't, template cached after first compilation.
i recommend have jade's source code better understand how 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
Comments
Post a Comment