title: Why does JavaScript setTimeout lag when in another tab?
body: <p>I am using setTimeout to run a JavaScript program that will use AJAX to fetch external data and update the content of the page once every 1000 milliseconds, or one second.</p>
  
  <p>This works perfectly fine when the tab that my web page is on is in the forefront. However, if the page is running in a browser window with multiple tabs, and the user is not currently in that tab, then the setTimeout will begin to lag (in one minute, rather than updating 60 times, it only updates around 30).</p>
  
  <p>However, if the web page is in the forefront of a browser window that is in the background, then setTimeout will continue to run at the correct speed.</p>
  
  <p>Can someone please explain why this is happening, and any ways to resolve this?</p>