title: What could explain the browser intermittently not loading some CORS (crossorigin) javascript files?
body: <p>I recently added the crossorigin attribute to certain script tags to enable my scripts to gather error information from scripts from a different subdomain. I added the header in nginx to allow the cross-origin request.</p>
  
  <p>Since then, I occasionally have a page load without the browser requesting certain javascript files from the server. Reloading the page resolves the issue, but this has happened several times now.</p>
  
  <p>I think this is related to CORS, but since it works most of the time, I have no idea how to reproduce it.</p>
  
  <p>Here are some excerpts from my code:</p>
  
  <p>Nginx configuration contains this rule for javascript files in a certain location:</p>
  
  <pre><code>add_header 'Access-Control-Allow-Origin' "$http_origin";
  </code></pre>
  
  <p>My script tag in the php page:</p>
  
  <pre><code>&lt;script type="text/javascript" src="&lt;?php print "$host/js/$filename?v=$version";?&gt;" crossorigin&gt;&lt;/script&gt;
  </code></pre>
  
  <p>When my page loads, I can see in Firebug that the script tag is correct, but in the Firebug Net tab there isn't even a request shown. Normally there is a request shown, even if it uses a cached version of the file.</p>
  
  <p>I found one question here which I thought might be related:
  <a href="https://stackoverflow.com/questions/14228839/all-of-my-browsers-are-not-sending-the-origin-header/14238351#14238351">all of my browsers are not sending the origin header</a>
  But thinking about it further, I think there should be an initial request which would fail and which would show in Firebug.</p>
  
  <p>Does anyone have any theories on why this might be happening?</p>
  
  <p>Edit:
  I added a separate access log for my CORS requests. Any file in the location which gets Nginx adding the CORS header also gets logged in a new access log.</p>
  
  <p>When the page fails to load a javascript file, Nginx is logging a request with a 304 status (not modified). That means that Nginx got a conditional request for the resource only if modified, and Nginx sent back the 304 and nothing else. If the cached version was not loaded with the CORS header, then maybe the javascript can not be executed.</p>
  
  <p>I have a version number which I append to the src of the script tag as shown above. This version number has changed. So shouldn't that cause the browser to re-request all these resources as if they had a different file name? I think the browser should have been treating these as uncached resources. There should not have been any requests that could result in a 304. What could be causing this?</p>