Enabling CORS

If your page loads scripts from a CDN or a different domain, You might come across meaningless Script error on line 0, with no additional data. These unhelpful messages occur because browsers traditionally don't provide access to error data if the script violates the same-origin policy. To solve this, you will only need to make two little changes to your existing setup.

Send the CORS headers for your script files

You can fix this by enabling CORS which bypass the same-origin policy in a secure way. Update your CDN or server configuration to send an CORS HTTP header with the response for your script files. The header should look as follows:

Access-Control-Allow-Origin: YOUR_DOMAIN

(or)

Access-Control-Allow-Origin: *
Modify your script tags

You have to add a crossorigin attribute to the script tag as follows

<script src="https://5kjfafd3.cloundfront.com/script.js" crossorigin="anonymous"></script>

Heads up! You must specify both the HTTP header and the crossorigin attribute for this to work correctly. Specifying only one or the other will cause the browser to not evaluate your code.