isomorphic-javascriptangular2-universal

Do the isomorphic apps implies back and front stand together?


I've been getting into isomorphic applications development with Angular 2 Universal but there is this thing that i cannot get clear in my head.

My understanding is that keeping back and front sides on different modules is a good practice, but it doesn't seem to be a common pattern when working with MEAN applications.

So, i am about to start a project that could scale and i'd want to implement the server side rendering in a future but i don't know which approach i should go with. Honestly i feel more comfortable keeping both backend and frontend on separate but, if so, will it be possible to implement server-side rendering later on?

Besides, supposing that i duplicate the index.html in both sides, will the server be able to delegate the control to the client when the first server rendering is completed? I mean, i can't imagine how that would that delegation work given the fact that they are not in the same project.

Thanks in advance.


Solution

  • As I understand, you are talking about rendering the UI and this is frontend part of your application, even if you do the pre-rendering work on the server.

    This pre-rendering is only optimization, you can keep it in some separate code layer, but I believe that the whole idea of the isomorphic javascript is to re-use the same code on the client and server. This way trying to duplicate code and/or templates is not a good idea (it never is).

    If you really want to keep things separated, think on splitting your application into more services:

    This way, initially the "frontend server application" can be simple proxy between the "frontend" and "backend server application". Later on you can extend it with server-side rendering.

    Important note: if you are going to develop application without pre-rendering on the server and add this on a later stage, you need to take into account that not all the browser-side javascript features will work on the server (for example, manipulations with native DOM elements), see the best practices section in angular universal readme.