D
D
Daniel Newman2017-04-07 11:13:23
Nginx
Daniel Newman, 2017-04-07 11:13:23

What is CSS decoding without encoding in cp1251 Chrome?

Haven't tested it in other browsers, but the gist is that nginx is configured, by default, as utf-8.
And everything goes smoothly until it comes to CSS with Cyrillic. Type:
[data-trainbrand="САПСАН"] {}
In my chrome it turns into something like (this is not my coding pair, but for clarity
[data-trainbrand="‘ЂЏ‘ЂЌ"] {}
Content-Type is "text/css" and nothing else. No utf-8 or cp1251.
I don't really understand the further mechanics of the browser with this mess,
but, of course, none of those converted from utf-8 to cp1251 will
work on HTML utf-8.
I solved the problem by setting the following piece of the nginx config hard through the server directive:

location ~ \.css {
    proxy_hide_header Content-Type;
    add_header Content-Type "text/css; charset=UTF-8";
}

А теперь вопросы:

— Почему кусок конфига из документации, не выставляет кодировку в Content-Type
— С какого Chrome решает, что нужно декодировать документ в локальную виндовую кодировку

<code lang="nginx">
include        conf/win-utf
charset        utf-8;
source_charset utf-8;
</code>

Спасибо.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Feninets, 2017-04-07
@fnnzzz

perhaps the file itself is saved in cp1251
In the sublime, you can change the encoding
FIle -> Save with encoding -> UTF8 with BOM

S
sim3x, 2017-04-07
@sim3x

In addition to converting the file itself from 1251 to utf8, it is worth adding https://developer.mozilla.org/en/docs/Web/CSS/@charset to the beginning of the file
@charset "UTF-8";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question