【问题标题】:EJS view engine with express - View file load time带有 express 的 EJS 视图引擎 - 查看文件加载时间
【发布时间】:2018-01-10 01:19:14
【问题描述】:

我正在使用 ejs 视图引擎进行快递。我的所有视图都存在于视图文件夹中。

app.set('view engine', 'ejs');

我的问题与渲染部分有关。我使用下面的行来渲染视图

res.render('pages/index');

我想确认的部分是是否

(1) express loads all views file in memory at the time of server start and then uses it for rendering view with variable subsitution or
  (2) whether at the time of rendering view it reads the content of the view file and renders it.

第一个显然是一个巨大的优化。我猜 express 遵循第一个方法,但只是想确认一下。

【问题讨论】:

    标签: express ejs


    【解决方案1】:

    在我看来,使用的是第二个。您可以在您的 ejs 文件夹中放置一百万个视图,而不会看到内存增加。

    【讨论】:

    • 其实我查看了express的代码。它会延迟加载视图文件并将其缓存。这就是为什么您没有看到内存增加,但如果所有视图都使用过一次,您会看到内存增加
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-09
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    • 2020-09-14
    相关资源
    最近更新 更多