Why does Angular2 require CORS when loading main.js from foreign server?

I get this error:

XMLHttpRequest cannot load http://otherwebsite.com/myapp/app/main.js.
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://otherwebsite.com' is therefore not allowed access.

when referencing a main.js file in Angular2:


But no other .js files require CORS pulled from the other site.

I know how to add CORS support for Web API 2 for methods but this is not a method. I know how to add CORS support for Apache folders in .htaccess files. And with a little digging I found how to add IIS 7 CORS folder support that made this error go away.

Buy why would Angular2 need CORS for my main.js when all the other .js files loaded without CORS issues?

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

If the script is loaded from another domain (which even means a different IP port) than index.html was initially loaded, then the server you request a file from, needs to provide the CORS headers, otherwise the browser won’t allow to fetch it.