Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn data or html for internal cakephp api?
    primarykey
    data
    text
    <p>I am interested in learning which of two options is optimal for a cakephp api I am building. The api is internal, i.e. is only used for our web site to communicate with the backend. The api is called via jquery, and I see one of two options for the return format:</p> <ol> <li>Return raw json, and leave it up to the jquery front-end to parse it and build the html.</li> <li>Return rendered html, so all the jquery needs to do is append the html to some container.</li> </ol> <p>Both options have their pros and cons. I'll list them here and maybe you can extend this list.</p> <p>Returning json:</p> <ul> <li>Pros: the front-end has complete freedom to do as it may wish with the data. For example, if we need to store data in jquery about each link, then we can do that as we loop through the results and build the html.</li> <li>Cons: I don't see a great solution as to where to store the html template for displaying the link. This is the reason I have thus far chosen Option 2. CakePHP has a very natural way of storing view templates and I exploited this feature. Embedding templates in the javascript is nasty!</li> </ul> <p>Return rendered html:</p> <ul> <li>Pros: Sort of the opposite of the above con; mainly, I can use CakePHP's built-in view-templating system to output the data.</li> <li><p>Cons: Cumbersome to store jquery data on each link to use later (like to register an onClick event). Currently, in each link html I include some code like this:</p> $('#this-link').data('someName', 'someData'); </li> </ul> <p>I am interested in hearing what others do to solve this issue. I've read that Twitter returns rendered html for performance reasons.</p> <p>Thanks everyone.</p> <p><strong>Update:</strong> I believe my question is partially solved by using a framework like <a href="http://documentcloud.github.com/backbone/" rel="nofollow">Backbone.js</a>. Still, if (for performance reasons), we want to render the html on the backend, then we'd need to still pass data via the api. So an example json response might look like:</p> <pre><code>{ id: 67, html: "&lt;a href=\"profile.php?id=61\"&gt;Who is number 67?&lt;/a&gt;" } </code></pre> <p>Still not ideal, I don't think. I'd prefer for the javascript frontend to magically understand it is #67 :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload