Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Being Converted to Chinese Characters

I have this simple angular app using angular 1.6.1.

index.html

<!DOCTYPE html>
<html ng-app="App">

<head>
    <title>Test</title>

    <script src="bower_components/angular/angular.js"></script>
    <script src="app/app.js"></script>
</head>

<body>
    <div>
        <home></home>
    </div>
</body>
</html>

app.js

(function() {

    'use strict';

    var app = angular.module('App', []);

    app.component('home', {
            template: '<h1>{{$ctrl.head}}</h1><ul><li>1</li><li>2</li></ul>',
            controller: function() {
                var vm = this;

                this.head = "ONE";
            }
        });
})();

This will load OK and display corretly in IE11, but fails to load on Chrome( 55.0.2883.87 beta (64-bit) or FF (51.0b13 (32-bit) and I have absolutly no idea why ....

whne I click on the app.js in Sources tab in Chrom Dev Tool the source is in wierd chineese like characters, but looking at source via Notepad++, all looks OK ... ?!?!

here is a screenshot of devconsole on chrome

enter image description here

I can see the same issue for every JS file I add to index.html. I didn't change any locale settings aor anything else in the browsers ot my PC ...

I have no idea why is this happening. Anyone seen anything like this?

like image 329
vidriduch Avatar asked Oct 18 '25 16:10

vidriduch


2 Answers

I had exactly the same problem. In my case, the main HTML page was in localhost and it was calling external .js files out of my control. The problem was present in modern versions of Chrome and Firefox (but not in Internet Explorer). I discovered that the HTML page had been accidentally created in Unicode, instead of UTF8 or ANSI. I used notepad.exe to save it as ANSI (since it was only in English) and that solved the problem.

like image 99
Joan Maso Avatar answered Oct 21 '25 04:10

Joan Maso


all files were created in command line by typing

echo "" >> app.js

and this has set encoding to UCS-2 LE BOM as displayed in Notepad++, and for some unknow reason Chrome and firefox could not read the files correctly ...

enter image description here

So converting file to UTF-8-BOM in Notepad++ (Menu -> Encoding -> Convert to UTF-8-BOM) file was read fine and all worked...

I would be still interested on why old IE managed to read the site OK, but more modern browsers failed ...

like image 31
vidriduch Avatar answered Oct 21 '25 05:10

vidriduch