async parallel request - partial render

后端 未结 2 1336
暗喜
暗喜 2021-02-10 17:23

What is the proper way to partially render a view following an async parallel request?

Currently I am doing the following

// an example using an object          


        
2条回答
  •  迷失自我
    2021-02-10 17:49

    I think you can't do it just on the backend.

    To minimise users' delay you need to send the minimal page to the browser and then to request the rest of the information from the browser via AJAX. Another approach to minimising delays is to send all templates to the browser on the first page load, together with the rendered page, and render all the pages in browser based on the data you request from the server. That's the way I do it. The beauty of nodejs is that you can use the same templating engine both in the backend and frontend and also share the modules.

    If your page is composed in such a way that the slow information is further in HTML than the fast information, you can write response partially without using res.render (that renders complete page) and use res.write instead. I don't think though that this approach deserves serious attention as you would stuck with it sooner than you notice...

提交回复
热议问题