title: Node.js: How to detect html embedded request vs XMLHttpRequest?
body: <p>In Node.js (or in any web server for that matter), is it somehow possible to be able to determine whether a resource request came from an embedded element in an html document, as opposed to a scripted request?</p>
  
  <p>For instance, if I have this in my .html file:</p>
  
  <pre><code>&lt;script src="/testRoute.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>And this in my javascript:</p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  xhr.open("GET", '/testRoute.js', true);
  xhr.send();
  </code></pre>
  
  <p>is there a way the server can distinguish between these two requests? </p>
  
  <p>The <strong><a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy" rel="nofollow">Same Origin Policy</a></strong> applies differently in each case, so there is apparently some differentiation going on (at least under the surface). Is there a way the server developer can see the difference?</p>
  
  <hr>
  
  <p>Just as a personal experiment, using a diff tool, I compared an <strong><a href="http://expressjs.com/" rel="nofollow">express</a></strong> <code>req</code> object received with each and saw only two slight differences:</p>
  
  <ol>
  <li><p>The <code>socket</code>, <code>connection</code>, and <code>client</code> properties in the
  <code>&lt;script&gt;</code> originating <code>req</code> object had <code>[function]</code>s for their <code>error</code> property,
  whereas these were <code>[object]</code> for the request that originated as an <code>XMLHttpRequest</code>.</p></li>
  <li><p>The <code>headers</code> property contained <code>cache-control: 'max-age=0'</code> in the request that originated as an <code>XMLHttpRequest</code> but not for the <code>&lt;script&gt;</code> request.</p></li>
  </ol>
  
  <p>I don't really know what that means, and I don't know if these results are consistent across browsers, but they were consistent at least between Chrome and Firefox.</p>