Reputation: 1617
This is not particularly a problematic programming query, as it is instead a best practise question.
When I write JavaScript, sometimes I make ajax requests, whether it be simple true/false request or some JSON. However, ocassionally, I am required to compile HTML so that, if for instance, the JavaScript were to load data for a page, it would compile data through JSON. Yet, I am having some mind-philosophasterings to whether I should maybe compile the HTML prehand, within my PHP? That way I can just dump the HTML on to the page, without making the JavaScript over heat itself.
Upvotes: 2
Views: 100
Reputation: 49612
Personally I usually return the data instead of preformated HTML. It saves bandwidth, it lets me format the data the way I need on that page and I can change the layout without touching the code that generates the data, I can reuse the data on another page and format it differently. (it also makes it easier for others to (ab)use your data)
Upvotes: 0
Reputation: 137332
Unless you have a massive number of DOM nodes to manipulate, I suggest you use ajax to move data and use JavaScript to work with the DOM. JavaScript will not overheat :)
I have used simple techniques like having a hidden template in the HTML that I copy (eg, using jQuery), update, and insert into the DOM.
Upvotes: 1