S
S
Sergey Korenevsky2019-09-20 12:37:19
JavaScript
Sergey Korenevsky, 2019-09-20 12:37:19

To prevent a JS timer from freezing in a Chrome tab?

I use an intervalset of 0.5 seconds. I fold and make a stopwatch in the browser.
After 3.5 hours I switch to the stopwatch tab, I see: 1.5 hours have passed ..
How to make the script not freeze?
How does VK do it for example?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Neverov, 2019-09-20
@TTATPuOT

Do not count via setInteval. Create a constant with the start date of the timer, and every N-times calculate the amount of time from the initial constant up to the current moment.

N
nvdfxx, 2019-09-20
@nvdfxx

webworkers can be used

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question