Render multiple pieces of content (blocks) in Node JS / Express JS without callback hell

I have a page which I render using res.render("/somepage", vars). vars is an object with results from a query. But what if I want to show an unrelated piece of content in a sidebar without creating a callback hell and include in vars the results of both queries? Using async/promises is not an option.

I'm using an approach which is to create only the main content and then get the sidebar content using jQuery $.get by calling a URL that returns a JSON object. This JSON object is the result from the other query, I create it using res.json(someQueryResult)

I blogged a more extensive explanation at http://lelizondo.tumblr.com/post/29971693078/holy-sh-batman-showing-async-blocks-of-data-from but I would like to know if there's a better approach, maybe using partials or some other technique I'm missing.

Thanks.

You may wish to consider something like Conductor.. http://howtonode.org/step-of-conductor

It may be more of a philosophy-of-development question. As the first commenter mentioned, it is wasteful in some sense to have two requests to the server to render a single page. However, if this is truly independent content from the main body, you probably DO want to avoid entangling the querying/rendering of it with your main content. This lets you maintain it separately (less risk of bugs) and potentially have different people (if you're in a team environment) working on the different 'widgets' that make up the page.

The only improvement I would suggest to your jQuery approach is to use something like underscore micro-templates to do the rendering of that JSON instead of manually building HTML.

The next step in that direction (like I said it's a bit of a philosophy issue) would be to use something like backbone.js on the client side and expand out your server-side route into a full REST API. Then theoretically it could even be coming from a different node.js server as your site grows.

And if you want to go all-in, there's always an approach like this