title: What does it mean to set a Content Security Policy on response to a non-HTML request?
body: <p>I understand that I might set a CSP header for the main page of my site, say <code>https://example.com</code>, to restrict from where I can load scripts and other resources. But, if there is <strong>no CSP</strong> on the main page, how will the browser treat a policy on a subsequent request?</p>
  
  <p>This is two examples in one:</p>
  
  <ol>
  <li>I browse to <code>https://example.com</code> and get back some HTML (no CSP header)</li>
  <li>The HTML includes a script from <code>https://example.com/script.js</code> [*]</li>
  <li>This script requests some data from the API by issuing a GET to <code>https://api.example.com</code> [*]</li>
  <li>The same script then opens a websocket to the same domain, <code>https://api.example.com</code></li>
  <li>The same script then makes another request, POSTing externally to <code>https://api.analytics.com</code></li>
  </ol>
  
  <p>[*] In steps 2 and 3, what would happen if the script.js or the JSON response came back with a restrictve CSP, like <code>Content-Security-Policy: default-src 'none'</code>? Would any downstream requests be changed? Does the browser do anything to prevent any of the script's requests? Or are the allowed because the original page load did not include any CSP?</p>
  
  <p>Thanks!</p>