Avoid cryptic javascript "script error" using cdn

I am using a script that detects Javascript errors and sends them to my server. However, I get cryptic "script error" messages, which is not very useful for debugging.

According to Cryptic, โ€œScript Error.โ€ Is reported in Javascript in Chrome and Firefox , the reason is because the script that threw the error was submitted from a different source than my site.

Since I use CDN, all my scripts are efficiently served from another domain. Is there a way to get more useful error messages when using CDN?

Everything is also served over SSL, so I would like to keep this feature.

+4
source share
2 answers

I had a similar problem: my scripts are served by a subdomain and fall under the same restriction. However, I solved this:

1) adding each script tag as follows:

<script type="text/javascript" src="http://subdomain.mydomain.tld" crossorigin="*.mydomain.tld" /> 

2) by modifying apache httpd.conf, adding the following inside each vhost (you should enbable mod_headers):

 <IfModule mod_headers.c> Header add Access-Control-Allow-Origin "*.mydomain.tld" </IfModule> 

On one of my servers I was not able to execute this functionality, except for the replacement

 *.mydomain.tld 

by

 * 

Be aware of the drawbacks that potentially allow * the dissemination of information about the fish. Documentation about CORS, same origin, img and fonts, cdn is available, but less is available about crossorigin script tags.

Hope this helps ...

+1
source

Try using jsonp for the dataType attribute in jQuery.ajax . The remote server must also support jsonp. This will cost browser security by preventing XSS.

Alternatively, you can use an IFrame and use jQuery in each window, but use HTML5 postMessage to communicate between windows on two different domains.

Or, if you manage both servers, you can set headers for the same source .

Jsonp was my weapon of choice for this problem. The rest are just legal.

0
source

All Articles