title: Is there an easy way to run Firebase in a web worker?
body: <p>I have a single page React application which consists of many files, bundled with gulp/browserify.</p>
  
  <p>Firebase javascript is embedded in this bundle.</p>
  
  <p><strong>I'd like to know if there is an <em>easy</em> way to run certain Firebase operations on another worker thread ?</strong></p>
  
  <hr>
  
  <p>What I have tried :</p>
  
  <p>Setting up a worker and sending the Firebase object, or instance, <em>via</em> <code>worker.postMessage(xxx)</code>. In both cases, it throws an error which says <code>the object cannot be cloned</code>. Example bellow with the Firebase object.</p>
  
  <pre><code>var blobURL = URL.createObjectURL(new Blob([ '(',
      (function() {
          var onmessage = function(event) {
              var FB = new event.data.Firebase('my firebase URL');
              // Here, some Firebase operations
              // ...
          };
      }).toString(),
  ')()' ], { type: 'application/javascript' }));
  var postViewedWorker = new Worker(blobURL);
  URL.revokeObjectURL(blobURL);
  
  [... later on ...]
  
  postViewedWorker.postMessage({Firebase: Firebase, ...otherParams});
  </code></pre>
  
  <p>In the above example, the Worker works (haha) until I try to pass Firebase.</p>
  
  <hr>
  
  <p>What I would like to avoid :</p>
  
  <p>Setting two completely different bundles, one with the main application, and one dedicated to all Firebase operations, with a helper lib to send operations from one another.</p>
  
  <hr>
  
  <p><em>Note : The reason behind this question is because my UI is slowed by Firebase operations. For example, I have a list of items displayed on a page, and when I scroll, each time an item is visible, the <code>view</code> count of this object is updated with Firebase. The page scrolling is smooth without those operations, and becomes jerky when I add them.</em></p>
  
  <p><em>Edit: Also, I consistently get the following warning : <code>Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.</code></em></p>