user1584421
user1584421

Reputation: 3863

Notification server to client, post a res.render(), after a time-intensive function has ended

When a user follows a route in my application, a time consuming function begins executing.

Can i render a page on that route in the beginning of the request, then when the time-intensive function ends, send something to that page, a message, to notify the user that the time-intensive work is done?

And then, when the page that the user is on, receives the message, it displays a hidden div with a link?

Are Flash messages able to do that?

Upvotes: 0

Views: 115

Answers (2)

Teneff
Teneff

Reputation: 32148

You can use WebSocket or event better Server Sent Events.

Take a look at sse-express

edit I've created a simple working example

Upvotes: 1

Ashish
Ashish

Reputation: 643

You can have a div in your page which will make a AJAX request to you time consuming API once the API sends the response your div will get populated with the data sent by your API.

So, The rendering process can happen in following way:

  1. You render a page as soon as the request has made
  2. The div on the page makes an AJAX request to time consuming API
  3. Once API in step 2 successfully respond the div gets populated with the data

Upvotes: 0

Related Questions