I want to send the <head> containing stylesheets before processing the rest of the page. In PHP, I could use ob_flush().
I tried doing something like this:
app.set('view engine','ejs');
app.get('*',function(req,res){
res.writeHead(200,{'Content-Type':'text/html'});
res.write('<!doctype...<link rel=stylesheet...');
doDBStuff()
.then(function(data){
res.render('index',{...}); // uses EJS for templating
});
});
However, the res.render() part does not get sent. Is there a built-in way to send chunked data?
One way to do it would be to manually load the EJS files and manually process them. I would also have to manually send the appropriate headers. I prefer a build-in method if it exists.
res.render()inside the callback of your db functions. As it is there, your render won't have anything to render. Can you add in what the shell of your db call looks like?