Refreshing API data every 10 seconds, setTimeout or more advanced options? #8610
-
For now I'm using setTimeout to fetch data from the server every 10 seconds, there is no need (or budget) to implement a websockets system. I'm wondering if using setTimeout has hidden gotchas or potential issues? Or can I use this just fine?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There is nothing wrong with running a timer every 10 seconds like you are. I use them for apps where websockets are not possible. Only issue I have run into is you need to make certain the first timer expires before setting another one. Too many timers running and you can see an impact on the browser rendering. I usually do a clearTimeout(myTimer) before calling another one. |
Beta Was this translation helpful? Give feedback.
There is nothing wrong with running a timer every 10 seconds like you are. I use them for apps where websockets are not possible. Only issue I have run into is you need to make certain the first timer expires before setting another one. Too many timers running and you can see an impact on the browser rendering. I usually do a clearTimeout(myTimer) before calling another one.