S
S
Sergey Pronin2016-06-17 08:55:56
JavaScript
Sergey Pronin, 2016-06-17 08:55:56

Why does the browser incorrectly perceive the encoding of the js file?

Node v6.2 using gulp creates a js file, then sends it in the standard way via express

app.use('/public',express.static(__dirname + '/public'));

As far as I understand from the documentation, it should give it in utf-8 encoding, although the encoding is not specified in the browser header.
Content-Type: application/javascript
When I work directly with the server, the encoding is correctly recognized in any utf-8 browser, even if I specify in
<meta charset="window-1251">
But when I connect js to on another site, then the whole Russian language turns into cryosyabry and the browser accepts the js file in 125 encoding
. Everything revolves on СentOS, on which the default is also UTF-8

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Inishev, 2016-06-17
@inish777

You can try to specify the encoding in the header
Content-Type: application/javascript; charset=utf8

A
Andrey, 2020-03-24
@AndryG

If you add a BOM tag to the .js file, the browser will come to its senses and read the script as UTF8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question