0

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>
<html>
  <head>
    <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>
  </head>
    <body>  
    <script>
    document.writeln("Got my ");
    </script>
    web page content
    </body>
</html>

The one line script.js consists of

alert('x');

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

alert('x');

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

2
  • 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, 2018 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, 2018 at 19:30

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .