0
votes

Hi I am developing a widget module in my existing Angular 1 based UI project. This widget is supposed to contain real time information.

As per my design, I want to send html view to client from node server(maybe using express js) when the first request is made. But as the data needs to be real time, I cant afford to send the complete html every minute(will be duplicate template transfer each time).

So is it possible that I send a template to client along with a set of java-script functions so that when ever client wants that data to be refreshed, he will just invoke the sent javascript function and internally my javascript function will make a rest call, get the json response from server and again repopulate the html sent initially.

This way I am planning to have initial rendering at server side and subsequent rendering at client using the logic provided by server. Here client will not be aware of which widget it is rendering and what functionalities it has. All those will be controlled by js sent from server.

Please do let me know how to achieve this as I find ejs not serving this purpose. With ejs, I need to have all logic to server side only. Whereas I plan to transfer logic from server to client at run time.

Also if my design is having some serious problems, do suggest some other alternatives. Thanks

1

1 Answers

0
votes

Angular1 is not server side rendering friendly as it needs browser DOM. Use of any templating engines wouldnt help either as the html generated by them are not picked up by the angular app.

Use a phantomjs headless browser instance to generate html by running ur angular1 app code and then angular will run in client side when scripts have loaded.

I would recommend switching to Angular2 or React as they are server side rendering friendly