Reputation: 913
From Express documentation:
The view engine cache does not cache the contents of the template’s output, only the underlying template itself. The view is still re-rendered with every request even when the cache is on.
Honestly, I did not understand what caching doing for performance improving. So I'll ask directly about what I worry that could cause the performance impact. Does caching help to avoid the performance impact because of below mixin and/or JavaScript code?
mixin TestMixin(parameters)
-
const {
hasIcon = false,
contextClass
} = parameters;
// Some thousands lines of JavaScript code width parameters validation and computings ...
div The content of this mixin could be arbitrarily large.
// ↑ Does caching reduce the performance impact because of above mixin initialization?
// (well, it's JavaScript "identifiers resolution")
In real project, instead of TestMixin
could be several thousands of UI components, implemented in Pug mixins. I was not critical when I compiled pug to html locally, but I suppose the compiling Pug to html in real time in server side requires the reconsideration of Pug includes usage.
Upvotes: 1
Views: 719
Reputation: 2365
You won't need a template engine if you're fetching a small amount of data from an API, or if you're making a small static site. The template engine allows you to reuse static web page elements while defining dynamic elements based on your data. You're more likely to benefit from a template engine if your site or web application is data-driven.
Yes, there is a drawback of using this as it increases the compile-time on every dynamic data request. Caching, will not help much in such a case as we render a new page with the new data on every new request. Caching will only help for static HTML files or rather templates. An overall slow page rendering. Moreover, the templates are compiled on the server-side.
Anyway, there are alternatives available for such cases, nowadays, the market offers a lot of front-end frameworks which do lot more than templating, for example, front-end frameworks like Angular offers declarative templates, dependency injection, end-to-end tooling, and integrated best practices to solve development challenges.
And also in the case of template engines server compiles template engines like Pug/EJS to HTML then sends it to the client which makes it a slow process if your site is growing heavy gradually and eventually, unlike client-side frameworks like angular, react, vue.js, where HTML pages are rendered on client-side(i.e browser) making it way more faster and efficient than template engines. You experience fast website rendering after the initial load. With it, caching static resources is going to addon an additional benefit.
Upvotes: 2