Search code examples
angularjsnode.jshandlebars.jspugtemplating

Front end templates vs. back end templates


Why is there template engines for both client side and server side? Isn't it natural to deal with routing on the server side? In what cases is it best to do routing and templating on server side? And on client side? And is there cases where you want to use both?

I have looked around, but nothing I have found explains this in a simple way. I guess I'm missing something.

Thanks!


Solution

  • Let me take your questions one by one:

    Why is there template engines for both client side and server side? Simple, to reduce the load on server-side! Imagine, thousands of users requesting to the server-side engine (let me call it web/app server) and all the requests are processed and served from the server cluster (at the expense of the host). Believe me, it's very expensive from server point of view. Another option is to just provide the data to the client engine, who does the presentation logic. Since it's a single user data/logic in the client, it's light-weight and fast. The key thing is that it reduces the load on server.

    Isn't it natural to deal with routing on the server side? It's not only natural, but a must to do (start with) server-side. But, as explained, doing the presentation logic at client-side makes the user experience better. That's how Single Page Applications with client-side framework like AngularJS came to being!

    In what cases is it best to do routing and templating on server side? The term templating is not used in the case of server-side. However, presentation template (layout and components) is mainly done on client-side and functional template (data) is on server-side. Server-side templating is nothing but web service (API).

    And on client side? As explained, all presentation layer stuffs (HTML, CSS, JavaScript).

    And is there cases where you want to use both? I would say, in all cases. However, the best candidate is a web portal, rather than a website.

    Hope I understand your question and my answers are helpful.