This is a weird one. I have devised a minimal web page http://localhost/Default.htm on a Windows 10 IIS server that demonstrates the error.

<!DOCTYPE html>
    <script src="script.js"></script>
    <link href="script.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    document.writeln("Got my ");
    web page content

The one line script.js consists of


The css file is

body {
  font-family: arial;

The jquery link is to check external sources.

On Chrome the page loads and then downloads the 3 files. The page shows

Got my web page content

The alert did not show and the css styling did not work

The JQuery script is OK. The script.js file throws an error

Uncaught SyntaxError: Invalid or unexpected token

The response is surprising


The response headers look OK

HTTP/1.1 304 Not Modified
Accept-Ranges: bytes
ETag: "f4cca4492325d41:0"
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Thu, 26 Jul 2018 23:49:32 GMT

Chrome throws a second error for the in-page-script.js. This is a plugin for Ember.js

Uncaught SyntaxError: Invalid or unexpected token

The content is lots of


The script.css file is similar


Now if I load the files individually in the same chrome browser (in Developer Tools > Network > right click on script.js and Open in a new window)

They are correct. It issue only seems to be apparent with page linked files.

FireFox loads all the files but throws similar errors as Chrome

SyntaxError: illegal character[Learn More] script.js:1:2

The response is


IE and Edge just work and don't have any issues (I never thought I'd say that) with this page.

Remedial actions I've played around with Application Pools, encodings, cachings, disk encryption, mime types. Nothing I have tried works. I think I have corrupted IIS some how in working with iisnode as this is the second IIS server that has had the same issue. The earlier server affected all web browsers equally resulting in the same Chinese/Korean/Japanese characters.

I'm at a loss. Any clues would be helpful

  • Can you use a tool like Notepad++ to check the encoding of your script files? If they are in wrong encoding, then the browser might not be able to parse them, and show you such garbled characters. – Lex Li Jul 27 '18 at 14:16
  • VSC says all .js and .css files are UTF8 but the Default.htm file is UTF-16 LE as guessed from content. – nsharrok Jul 29 '18 at 19:30

Thank you Lex Li.

It turns out that the encoding of the page referencing the script or css file has an influence over how the file content is interpreted in the browser.

The script tag used to have a charset attribute (depreciated) which when not present defaulted to the charset of the page for Chrome and possibly Firefox. Perhaps they still determine the charset of the referenced js or css file by using the charset of the referencing page.

It looks like Edge (and IE), FF and Chrome do this charset interpretation differently.

I changed the charset of the Default.htm page and the page worked. I was looking in the wrong place (the js and css files). How the Default.htm file got to be encoded in UTF16 LE is a mystery to me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.