Something bothers me about Facebook timer

If you used Facebook, you may notice that there is a timer in everything that appears on the page, which is constantly updated in a matter of minutes. Which, I wonder, does not affect the performance of the website.

Regardless of whether it is an Ajax request, initiated by a timer, or simply a client-side cache, many timers are used. You do not use many timers, how does this affect the performance of the site? or something is missing me.

+3
source share
2 answers

What Facebook does requires only one timer. Each time it fires, it iterates through all the elements abbrwith class="timestampand calculates the update based on the user attribute data-datethat they defined.

+3
source

Of course, everything you add that launches setInterval()will change website performance.

However, if Facebook does not show the time until the second, it probably works once a minute.

I also noticed that Facebook uses a lot of fuzzy times, for example, just then, etc. This may mean that it setInterval()works on an even larger interval.

0
source

Source: https://habr.com/ru/post/1777278/


All Articles