C
C
Cat Scientist2015-10-12 00:23:51
PHP
Cat Scientist, 2015-10-12 00:23:51

Should I use EJS on the server using PHP?

We are talking about a REST-like MVC web resource architecture, in which EJS acts as a template engine . It's easier to show an example than to explain the details:
In response to a request http://example.com/categoriesor, for example, the http://example.com/posts/100500server will send to the client text/html, and in response to http://example.com/categories.jsonand http://example.com/posts/100500.json- application/json. Accordingly, in the first case, the template is processed on the server, and in the second case, directly on the client. Let's say we feed all internal links with the event onclick, and the once-written callback function makes an AJAX request and updates the DOM using our template engine and the same template file in the client browser.
If we are writing in node.js this would be a stupid question, but we are writing in PHP and is it advisable to use PHP's V8 implementationto create this architecture is a reasonable question.
Here are my thoughts on this:

  1. Pros:
    1. Code reuse. The template is written once.
    2. Easier support and extensibility. It follows from the previous one.
    3. One controller / action per entity - by condition either renders the template or gives json to the client.
    4. The template is processed on the server only on initial page load. In the future, the client receives only data. It makes sense for web applications - it reduces traffic and load on the server.
  2. Minuses:
    1. There are doubts about the advisability of using another interpreter on top of the second.
    2. It makes no sense for one-page non-interactive resources such as landing pages.

I like this idea, but it looks like a gamble. I trust in your experience, fathers. Your opinions please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Evgrafovich, 2015-10-12
@Tantacula

And what's the point of processing the template on the client and on the server, if you can process it only on the client or only on the server?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question