Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Gonras Karols
Gonras Karols
17,357 Points

Conceptual web question

Let's say i have 2 dropdowns in my html file , each of them has a list of operators that can also be found in the database.. every time a user chooses 2 operators - a comparison table will be shown right below the dropdowns , that will be populated from the database ..

i managed to do the whole cycle of html->javascript (ajax)->php->back to html. but my question is - should the table be generated within the php file using strings that will have the whole "<table>" thing.. or should the table be generated within the javascript? (for example - var table += '<table><th>'+response['operator_name']+'</th></table>;) and then should be attached with jquery to some div below the dropdowns?... or maybe the table's template itself should be already written statically in the html and only its' cells should be populated as a result of the ajax' response ?

1 Answer

Steven Parker
Steven Parker
231,007 Points

:point_right: There will often be many approaches to the same problem.

Most non-trivial problems will have several equally valid ways to resolution, and it sounds like you've identified a few that would all address your issue. The choice usually boils down to two factors:

  • Fastest development time / most compact code
  • Fastest performance

If you're lucky, you can accomplish both with the same approach, but most likely the choice will involve some trade-off between these factors. In those cases, picking the best blend of both concerns might do unless the situation warrants specific focus on one factor over the other.

Gonras Karols
Gonras Karols
17,357 Points

Yeah, i get it, but still.. isn't there a more common approach when it comes to processing data in the DB and send it back to the client side?.. The most important factor here is fast performances.. what takes longer? to create the elements on the backend and simply return a whole html batch to the front, or should i attach the response to different elements using jQuery?