Js deals with the data returned by ajax. How to render it?

which is better to concatenate strings or to use a template engine.

or how to package node rendered with ejs into a static file

May.30,2022

first question: ajax and template engine are two ways of interaction, each has its own advantages and disadvantages, and the application scenarios are not the same.

  • ajax is an asynchronous interaction, which can be partially refreshed. If an error is returned, it will not affect the rendering of other pages. The disadvantage is that manipulating elements requires a large number of selectors or splicing element strings, which is troublesome to develop, but most front-ends have this technology, and the training cost is low
  • .
  • template engine, high development efficiency, fast back-end learning, most front-end can not be maintained, but also need to train template syntax (not easy to use).

take our company as an example. Because the first page is visited frequently, the freemarck template engine is used to compile the page into a static file, add a timer to the generated control class, generate a static file in half an hour, and replace the first page in the project (the cluster needs to add a synchronization mechanism), so that the page can be static. Try to avoid calling the back-end interface
when loading pages, and use ajax interaction on other pages that do not require compatibility with high concurrent loading, which is more flexible

.

second question: node uses ejs to render
you can search for specific instances. There are many downloadable projects on the Internet for rendering static files

.
Menu