On some servers, many external resources (GA, fonts.com fonts, etc.) error out with "Uncaught SyntaxError: Unexpected token ILLEGAL"?

On a few servers I've worked with, many (but not all) of my externally loaded resources error out and throw (in Chrome) "Uncaught SyntaxError: Unexpected token ILLEGAL".

Including jQuery from the googleapis CDN works fine, but loading a fonts.com JavaScript font file and loading the basic Google Analytics code both error out.

Here's the code (also, here's a fiddle if it helps):

        <script type="text/javascript" src="http://fast.fonts.com/jsapi/dd7c6b7d-1ecb-4ef4-bf65-c4759f97cbe3.js"></script>
        <script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>
        <h2>This is a test of the emergency broadcast system.  This is only a test.  If this had been an actual emergency, the tones you just heard would have been followed by official news or instructions.</h2>

The headers from these files transfer as text/javascript.

Finally, when I view the resource within the Web Inspector's Resources tab, I see some non-Roman characters instead of the actual code of those files, so that makes me think there must be some sort of encoding issue. I tried setting the charset to both utf-8 and iso-8859-1 in the document head (using meta charset) and neither helped.


Well, I think I've solved the problem: My primary HTML page (not the included scripts) had, at some point, become encoded as UTF-16. I changed its encoding (not using meta charset, but by editing the encoding of the document itself using my code editor) back to the default, Western (ISO Latin 1), which I assume is the same as iso-8859-1.

My best guess is that at some point I pasted something into this file that had UTF-16 encoding, my editor converted the document's encoding to UTF-16, and then the site assumed the external resources it was importing were also UTF-16, which caused it to misinterpret them.

I'll leave this question & answer up in case someone runs into the same problem.

Need Your Help

Login to App using Json Data iOS

ios json wcf login

Another question about parsing Json Data.