Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome displays JavaScript file in what appears to be Chinese

Screen Shot of Problem

Chrome js file

My html

<!DOCTYPE html>
  <html>
    <head>
  <title></title>
    </head>
    <body>
  <script src="scripts/vendor/require.js"></script>
    </body>
  </html>

The js file

var d;

That is all there is. The file used to be require.js from their main site. But I deleted everything trying to figure out what was going on. I then deleted the whole file and created a new file (with the same name). Could I have changed something with Chrome to make in interpret files this way? I can't reproduce the problem with any of my other projects. I also originally downloaded the file using jam. Really I could just start a new project folder and probably solve the problem but I am curious as to why it would do this. Maybe something stupid simple since I am new to this.

like image 564
dylntrnr Avatar asked Feb 15 '13 18:02

dylntrnr


2 Answers

It was a encoding problem with my index.html file (I re-saved the file with UTF-8 encoding and the problem went away). Thanks for your help.

like image 157
dylntrnr Avatar answered Sep 19 '22 00:09

dylntrnr


The problem is that the master file and the linked script file must have the same encoding, otherwise Chrome browser will not be able to load it correctly.

For example, if the html file is encoded in UTF-16 LE and the javascript file in UTF-8, then Chrome will silently assume that the javascript file is also in UTF-16 LE and fails to load it.

You can add a charset attribute to the script element to hint about encoding and in such case, Chrome will load it correctly:

<html>
  <head><title>Test</title>  </head>
  <body>
    <script type="text/javascript" charset="UTF-8" src="script.js"></script>
  </body>
</html>
like image 25
P-39 Airacobra Avatar answered Sep 18 '22 00:09

P-39 Airacobra