简体   繁体   中英

The technical problem “ejs” trying to solve

Because all Angular & React does similar type of templating behind the scene. So why use ejs..? Is that for project that do not use Angular/React and alike.?

React and Angular are tools initially built to create Client Side applications or Single Page Applications. This means that the client receives a single HTML file and one or more JS files that contain the app's code. All of the HTML that you then see generated in the website is actually built in the client (AKA the user's browser).

We now see both React and Angular being used for aplications that have their HTML built in the backend, either in run time (Server Side Rendering) or on build time (technically also Server Side Rendering but usually referred to as Static Site Generation, see Gatsby for an example).

EJS is a simpler tool, it basically just gets an HTML file (with the.ejs termination) and some placeholders {{data}} , and fills these with anything that we might want to use. What basically happens when you generate an HTML page to send to the client when using EJS is something along these lines:

index.ejs -> (In Node) Pass object with data values for placeholders -> Replace placeholders with actual values -> Output finished HTML file with value instead of placeholders

Notice that there is no special logic, state or any other complexity that you may find in a React or Angular application. It is a templating engine, it just does what was described in my snippet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM