I am looking for a solution to start viewing a web page while the request is not complete. For example, with Express and EJS, if I query multiple data sources (which I do not have the mastery), I have to wait to retrieve all the data I need to use before "res.render" .
Is it possible to send the top of the page and then blocks one by one ?
Thank's for your help !
You can't simply render half the page and wait for your data to finish loading page via server-side programming.
The best solution for what you are attempting to do is AJAX calls. Retrieving the data from the client side allows the user to see all the static content available without having to wait for the data-driven content to be fetched.
This isn't the best solution for your problem, which is to optimize your queries to your data sources.
Make a basic template and feed res.render() with this. That would be the first thing the user sees.
You have to code a client .js code (which you call with your 'basic' page). This one, on document.ready
will issue ajax calls to fetch the other pages. For that, you will need to enable other routes, each with their respective content.
The callback of the ajax calls must have a way to append the retrieved content into your 'basic page'.
That should do.
(Obviously, there are several ways to make this more complex and more professional, but methinks @LeGilles was looking for a 'kickstart').
Regards,
H.-