use*_*423 8 node.js express pug
框架:node.js/express.js/Jade
问题:在生产环境中,当一个jade文件由express呈现时,jade缓存就是这样,所以将来的渲染会更快.
当我启动node.js应用程序时,如何预编译(或)预渲染(如预热)所有的玉文件,以便在请求开始进入时它已经在缓存中...
我可以使用文件夹递归,我只需要知道如何预编译(或)预渲染.
这可能吗?
Jade内置了模板预编译和缓存.
只需指定cache: true选项jade.compileFile,然后遍历所有模板文件即可.
var options = {cache: true};
// iterate/recurse over your jade template files and compile them
jade.compileFile('./templates/foo.jade', options);
// Jade will load the compiled templates from cache (the file path is the key)
jade.renderFile('./templates/foo.jade');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4099 次 |
| 最近记录: |