Auto refresh a page in React.js

raksheetbhat picture raksheetbhat · Jan 3, 2018 · Viewed 18.6k times · Source

I need to continuously update/refresh my page to ensure that it is in sync with my server. Currently, I am using setInterval, but I read that serviceWorkers might solve my problem in a better way. Is it recommended to use serviceWorkers? (the background-sync seems like a good starting point.)

Or are there any other alternatives?

Answer

raksheetbhat picture raksheetbhat · Jun 7, 2018

After some research, WebSockets seem like the best bet to have a live refresh on a website. Websockets helps maintain an open two-way connection between the website and the server so that whenever there is an update on the server, the server can push the changes on to the website.