Ejs and Express.js - render ejs page first with default param values then rerender after params are calculated

TL;DR - Using ejs and express.js, how to render a page with default/empty variable values first before doing polling/interrupt to get the calculated variable values, possibly after 10 seconds or more.

Hi, I am new at making server-side webpages (have experience with automated client-side webapps) and found embedded js (ejs) along with express.js to be exactly what I needed for my website integrated with discord bot :slight_smile:
I have figured out how to set it up, and it is indeed looking beautiful.

However, the problem is that I am sending variables to my ejs page (through response.render(...)) and getting the values of these variables take more than 10 seconds (it could be up to 200 function calls or more to get the array values). Thus this latency of over 10 seconds reflects how slow the render() is for me.

I have tried rendering my page twice inside the .get() HTTP method and encountered an error, and rightly so since I’m sending 2 headers for 1 http request (or so I learned from the web). Some person said express.js is designed this way and I’ll have to modify express’ send() method and .end() method - this is too complicated for me.

Another person made a suggestion to render the page and then poll for values back from server. He didn’t mention on how to do this poll and communicate with the server though. And I admit that I have no idea on how to have a poll or interrupt to pass the finalised variable values to the webpage.

Any solutions above or any new solutions are much appreciated. Thank you in advance :slight_smile:

It seems the solution lies with using AJAX calls instead of rendering the file. I don’t have the details yet though. I’ll await for anyone who knows about this (or will finish learning AJAX later when I’m free)

o>

Update: I fixed my problem using AJAX. I suggest anyone in the future to look into AJAX for this kind of problems