Answer the question
In order to leave comments, you need to log in
How to generate dynamic html using node js?
Hello. How to generate dynamic code using a node itself. There are all sorts of template engines, etc. etc. I tried JADE, but there is a problem, if you hold down F5 in the browser when the page is open, then the CPU load is about 20% (core i7 3.5GHz) which is a lot, considering that this is only one client. That is, the generation of pages by the template engine takes a lot of resources for the node, what to do without them?
Answer the question
In order to leave comments, you need to log in
If the base is removed altogether, just compiling jade takes a lot of resources
//каждый раз делать
var html = jade.render('string of jade', merge(options, locals));
//Один раз при запуске приложения
var fn = jade.compile('string of jade', options);
//И дальше везде в коде вызывать
var html = fn(locals);
Cache in the RAM by the key and return from the cache, take the URL (for public resources) and URL+UserId (for user resources) as the key. Other than that, don't access the database on every request, don't access the disk on every request, write good asynchronous code.
Compile templates into js functions before starting the project, and use them in the project not as templates, but as code.
I don’t know about JADE (in theory it should be), but Handlebars definitely has
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question