M
M
mozart13372016-06-24 00:37:48
Node.js
mozart1337, 2016-06-24 00:37:48

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

3 answer(s)
A
Alexander Taratin, 2016-06-24
@mozart1337

If the base is removed altogether, just compiling jade takes a lot of resources

You probably don't cook right.
Not right
//каждый раз делать
var html = jade.render('string of jade', merge(options, locals));

Correctly
//Один раз при запуске приложения
var fn = jade.compile('string of jade', options);

//И дальше везде в коде вызывать
var html = fn(locals);

T
Timur Shemsedinov, 2016-06-24
@MarcusAurelius

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.

D
Dmitry Belyaev, 2016-06-24
@bingo347

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 question

Ask a Question

731 491 924 answers to any question