title: AJAX requests in Web Workers?
body: <p>In my web application, what the user does on the page have to be sent my database, so I have the latest changes saved.</p>
  
  <p>I just call the function with the request here when the user close the page:</p>
  
  <pre><code>window.onbeforeunload = sendData;
  </code></pre>
  
  <p>But where the problems come up is when I send data every 10 second. I do send my requests sync and not async (or it would not be sent <code>onbeforeunload</code>). The problem is that this adds delays to the user interface when the data is sent every 10 second.</p>
  
  <pre><code>setInterval(sendData,10000);
  </code></pre>
  
  <p>This is what's getting called:</p>
  
  <pre><code>function sendData(){
       var xhr = new XMLHttpRequest();
       var localData = datatodatabase;
       xhr.open("POST", "handler.php", false);
       xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
       xhr.send("pack="+datatodatabase);
  }
  </code></pre>
  
  <p>Is it possible to add this inside a Web Worker to make the synchronized requests stop delaying what everything else is going on?</p>
  
  <p>(As I said: I have to use synchronized because of <code>onbeforeunload</code>)</p>