gpt4 book ai didi

node.js/Jade - 如何预编译 jade 文件并缓存它?

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:56 28 4
gpt4 key购买 nike

框架:node.js/express.js/Jade

问题:在生产环境中,当一个 jade 文件被 express 渲染时,jade 缓存了它,所以 future 的渲染速度会更快。

当我启动 node.js 应用程序时,我如何预编译(或)预渲染(如预热)所有 jade 文件,以便在请求开始进入时它已经在缓存中...

我可以使用文件夹递归,我只需要知道如何预编译(或)预渲染。

这可能吗?

最佳答案

Jade 内置模板预编译和缓存。

http://jade-lang.com/api/

只需为 jade.compileFile 指定 cache: true 选项,并遍历所有模板文件。

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');

关于node.js/Jade - 如何预编译 jade 文件并缓存它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30689344/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com