3 ms·
This tag here: <meta charset="utf-8"> Is only strictly necessary if your web server isn't serving the charset as part of the content-type: content-ty
by simonw 2y ago
This tag here:
<meta charset="utf-8">
Is only strictly necessary if your web server isn't serving the charset as part of the content-type:
content-type: text/html; charset=utf-8
There's no harm in including it though, and it does at least mean that if your HTML page is saved offline it will definitely carry its charset information with it.
- o11c 2y agoI would say the opposite: putting critical information only in HTTP headers is dangerous; always put it in the actual file; in some cases a file extension is sufficient.
- csande17 2y agoIf you do want to ensure the file is interpreted as UTF-8 regardless of HTTP headers, the most efficient way is to place a U+FEFF "byte order mark" character (EF BB BF when encoded as UTF-8) at the start of the file. It's shorter than a meta tag, and it's the first thing browsers check for when loading a file (assuming they're following https://html.spec.whatwg.org/multipage/parsing.html#determining-the-character-encoding https://html.spec.whatwg.org/multipage/parsing.html#determin...).
- threatofrain 2y agoCould you explain the danger a little bit?
- o11c 2y agoChanging the encoding changes the meaning. If the encoding is only declared in a form that is easily lost during a standard action (downloading a file), that's bad.