title: How to fix cors error when loading static file served by Django runserver
body: <p>Relevant info : Django version 2.2</p>
  <p>I have installed <code>django-cors-headers</code> and added it to enabled apps and added the middleware to middleware settings as first middleware.</p>
  <p>I have also configured the settings:</p>
  <pre><code>
  INSTALLED_APPS = [
      ...
      &quot;corsheaders&quot;,
      &quot;rest_framework&quot;,
      &quot;django.contrib.admin&quot;,
      ...
  ]
  
  
  MIDDLEWARE = [
      ...
      &quot;corsheaders.middleware.CorsMiddleware&quot;,
      &quot;django.contrib.sessions.middleware.SessionMiddleware&quot;,
      &quot;django.middleware.common.CommonMiddleware&quot;,
      ...
  ]
  
  CORS_ORIGIN_ALLOW_ALL = True
  CORS_ALLOW_CREDENTIALS = True
  </code></pre>
  <p>My setup has 2 projects running on different ports. Django server running on 8000 and my front-end running on 8080.</p>
  <p>All API requests the front-end sends against back-end work just fine. But when I try to load one.js file served by the back-end project it fails with this error:</p>
  <pre><code>
  Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8000/static/myscript.js. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
  
  </code></pre>
  <p>The way I load the script is by creating a new script element and add the URL <code>http://127.0.0.1:8000/static/myscript.js</code> as value for the src attribute on the script tag.</p>
  <p>This error does not occur when I use a value like <code>https://code.jquery.com/jquery-3.5.1.min.js</code> instead of <code>http://127.0.0.1:8000/static/myscript.js</code> so it looks like there is some issue with static files being served by Django runserver, but what exactly and why is beyond me.</p>
  <p>I know that there is a bunch of cors related issues like <a href="https://stackoverflow.com/questions/55751033/django-cors-on-static-asset">Django CORS on static asset</a>, but they are not about my issue or have gone unanswered. Also, I noticed, that the requests going at static files bypass the cors middleware anyway, so perhaps I should be doing something else here instead?</p>
  <p>Perhaps someone can help me out here?</p>
  <p>Thanks</p>