6

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.

dylntrnr
  • 441
  • 5
  • 10
  • 2
    What encoding did you save the file as? What HTTP headers are sent with it? – SLaks Feb 15 '13 at 18:54
  • I updated the screen shot to include the HTTP headers. And I just saved it again with UTF-8 just to make sure (problem is still there). Thanks for the quick response. – dylntrnr Feb 15 '13 at 19:14
  • Could it be a Byte Order Mark? http://en.wikipedia.org/wiki/Byte_order_mark this is the kind of thing random unicode errors can cause – Jason Sperske Feb 15 '13 at 19:23
  • @SLaks I was assuming only the js file might have the encoding error when I first read your comment, but it was the index.html file. If you submit an answer I will accept yours since you were right about the problem. – dylntrnr Feb 15 '13 at 21:17

3 Answers3

9

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.

dylntrnr
  • 441
  • 5
  • 10
  • Thanks for posting your answer. You helped me solve a similar issue I had using PSDeploy to perform a transform on a HTML file on an automated build server: Turns out that where I was issuing my final `Out-File` statement, I had to include the flag `-Encoding "utf8"` in order for the output to have the correct encoding on the build server. – DatHydroGuy May 10 '17 at 15:19
2

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>
P-39 Airacobra
  • 229
  • 3
  • 9
0

it's definitely not a chrome problem (look at content-length: 6 ) did you try restarting your server after saving the file?

srosh
  • 124
  • 1
  • 3
  • you're right. I didn't mean a problem with chrome. I meant more in the sense: could I have changed a setting or something to make chrome interpret files in this way? I'll change my wording a bit in the question. – dylntrnr Feb 15 '13 at 19:26