rendrjs / rendr

Render your Backbone.js apps on the client and the server, using Node.js.
MIT License
4.09k stars 312 forks source link

Little help on the rendr usage. #433

Closed pcompassion closed 9 years ago

pcompassion commented 9 years ago

We have a website built with django + backbone.js + require.js

Yes, client rendering is slow and I found rendr.

Because I'm not familiar with node.js, I can't see how rendr fits in.

I get a feeling it's something like this.

client -> node.js node.js -> api server (return json, django in our case) node.js -> client (rendr does the rendering on server side and return rendered html, and populates backbone model/view/collection on client side)

so if I had a page which required multiple kinds of db hits. (a user page might need, what he wrote, what he like, what he commented, and so on) node.js would need to send multiple api calls to api server.
and everything has to be api end point.

Secondly, all the templating that was happening in django side (base template and each page that has require.js app) needs to be somehow moved to the node.js

Wouldn't it be possible doing the opposite?

client -> api-server (django) django -> node.js (give html and jsons and get populated html back. I'm thinking of node.js + rendr as something which can render html from html+js+json) django -> client

Has anyone integrated rendr + django ?
I'd like to get some hints how I should start thinking about it...

The direction I described (the reverse way: getting html from node.js rather than getting json from api server) would be doable?

saponifi3d commented 9 years ago

So, yeah, Rendr is built to plugin to an API (similar to how backbone does). The idea behind it is that there just needs to be one set of templates, hit the same endpoints a backbone app would, then do all the rendering in Rendr. A common templating engine people use with Rendr is handlebars because of rendr-handlebars.

The only reason why node really ties in, is because it servers the endpoints that you want, and makes the requests to the APIs.

The general flow is:

      Rendr (client)       Rendr (server - node)
             |               /
    api-proxy (node)        /
             |             /
 -----------------------------------
      API (in this case django)

Th idea of django giving html to node seeeemmmsss like it should work, by just setting the template as part of the json response, but that means you'll still need to have the templates in two places. (if i'm understanding your question correctly)

Let me know if you have any other questions or if you need more help. But, basically, Rendr is designed to talk to a JSON response from an API - I am willing to bet you can engineer some way to get around the fetch's and have it optionally rendr an HTML response from a server, but you'll have to go in and add some specific app functionality there.

pcompassion commented 9 years ago

Thanks for the detailed answer.

I have been experimenting the reverse way(instead of browser->node.js->django, we do browser->django->node.js) and I found a way to make it work.
Messiest part are jquery plugins which require document and such.

node.js is a renderer which takes html, js (data-main of requirejs for my case), json and outputs rendered html.
I borrowed the idea of marking the rendered html with view-id/model-id and setElement to make it work.

Thanks!