简体   繁体   中英

Update client-side information from server, without sending a request each time

I am currently developing my own desktop clock app and after successfully receiving the current date and time via custom API and locally, I've come to the point where serious complications may occur in the future.

With the current implementation of (local-time), the time is updated locally - every minute per app instance.

It would be unnecessary silly if I try to achieve the same for the (server-time) -> to send a GET request each minute to the Server from every existing app instance...

So, here comes my question..

What are the more efficient alternatives ?

PS The server environment is Node.js. The received time is in the form of a JSON.

you can try this code

 const serverTime = new Date(); // lets say this is time from server const timer = (time) =>{ setTimeout(()=>{ time.setSeconds(time.getSeconds() + 1); console.log(time) timer(time); },1000) } timer(serverTime); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM