-1

How do you handle the refresh of the clients when used in production environment? What I'm looking for to achieve is to force the production client to reload with the new source code when pushing an update to the servers

On local, I'm using hot reload but it doesn't seem to be recommended in production.

joknawe
  • 1,510
  • 11
  • 15
Flo
  • 1
  • 2
    Possible duplicate of [How can I force clients to refresh JavaScript files?](https://stackoverflow.com/questions/32414/how-can-i-force-clients-to-refresh-javascript-files) – Hamms Jul 13 '18 at 00:09
  • The above link is about preventing cache retrieval of out-of-date js, OP is asking about forcing a reload of an in-progress session. – Joshua R. Jul 13 '18 at 01:14

1 Answers1

0

To actually force a reload, you have a couple of options.

In broad strokes:

Your client script could poll your server via setInterval using a XHR request (fetch or XMLHTTPRequest object); then conditionally invoke a location.reload() if an update is available.

Alternatively, you could use a persistent connection like socket.io to push a reload command to your client in the background, invoking already-present reload-code in your client.

You might also consider keeping local application state in local storage so that the updated version can pick-up where the previous left-off.

Joshua R.
  • 2,282
  • 1
  • 18
  • 21