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

[Optimization] Fuse client fetcher http requests #207

Open trshafer opened 10 years ago

trshafer commented 10 years ago

Let's say I have a controller action which looks like

exports.show = function(params, callback) {
  var spec = {
    model: {model: 'Item', params: {id: params.id } }
    anotherModel: {model: 'AnotherItem', params: {id: params.otherId } }
    collection: {collection: 'SomeCollection'}
  };

  this.app.fetch(spec, function(err, result) {
    if (err) {
      return callback(err, result);
    }
  });
};

Assuming this was called by the client router, it will generate 3 separate http requests. This is ok on desktop, however on a mobile network, latency is the suck. It would be great if the client fetcher fused the requests into a single http request. It makes one request to, let's say, /api/bulk-request. Then the dataAdapter separates that http request and makes individual calls to each route, fusing the responses together, and pushing it back in a single response.

What do you think?

bigethan commented 10 years ago

I like this idea. I've been tinkering a little with trying to work oboe.js into the client dataAdapter/fetcher process so that we can start displaying results from the response sooner. Something like this would mean that the fetcher would have some more rules that could be leveraged.

trshafer commented 10 years ago

hey @bigethan, the response could totally be streamed as each internal api call finished. It wouldn't have to be sent as a single response. That just seemed more complicated. But would probably be better for use cases such as oboe, and it would allow the client to do any processing of the data at separate times opposed to all at once.

spikebrehm commented 10 years ago

Sorry I missed this (email settings...).

I like this idea a lot. I think this functionality should exist as a separate module that can be dropped into Rendr, rather than in the core. It could be a simple middleware, with a custom Model base class that knows how to serialize the URLs properly?