skybert's Blog

skybert's Avatar Image
Coder of systems, lover of languages, follower of Christ. 台灣女婿
← All posts

TIL the browser will grind your JavaScript to a crawl when the browser window isn’t active.


function sayHi() {
  var hi = document.createTextNode(new Date() + " Hi there!\n");
  document.getElementById("greetings").appendChild(hi);
}
setInterval(sayHi, 5000);

In my tests, Chrome will call it once a minute, whereas Firefox calls it twice a minute. Both are far away from the 5 seconds I thought I was getting 😃

#javascript #chrome #firefox #webdev

Showing how the browser executes the `setInterval` method every minute instead of the desired 5 seconds.
Showing how the browser executes the `setInterval` method every minute instead of the desired 5 seconds.
To like or reply, open original post on Emacs.ch