Build models in PHP or JAVASCRIPT?

1

The question seems to be obvious, but I would like to understand it in more technical terms. In my application I need to put objects in an HTML template, for user visualization. I have two options and I would like to know which one is the most efficient.

1 - Send only the objects for AJAX request and mount the HTML template in JAVASCRIPT and place it in the interface.

2 - Mount the HTML template in PHP send to AJAX request and just put it in the interface.

I'm currently using 2nd, but I think the first option is more efficient. I wonder if I'm right and why.

    
asked by anonymous 05.05.2018 / 19:11

1 answer

1

This question does not have an exact answer as I said in my comment on this question :

I generally believe the more on the client side the better, but there are cases where this can change, if your application is focused for users who do not have very powerful machines, a tool to be used with heavy applications or are you making an internal system for a sustainable enterprise that still uses windows xp

By doing a comparison between returning only the crucial data in JSON or ready html format (data, html tags, styles, ...), the first one will be clearly faster however it depends on whether you want to relieve the backend or the front-end

Even if you prefer to ease the front end, I believe it's worth more just to send the data in json format, and in html create the table if you need to do checks to, for example, change the background color of each line accordingly with a specific data of that line, you can do these if else / switch case in the back end and return it along with json the color of that line. The time lost when sending more data in general does not make up for leaving everything in the back

    
05.05.2018 / 19:19